Introduce the api-get command.

Review Request #4195 — Created June 2, 2013 and submitted

Information

RBTools
master

Reviewers

Introduce the api-get command.

The new rbt api-get command takes a path to an api resource, requests
the resource, and prints it as JSON. The path can either be rooted
at the api level (e.g. '/review-requests/123/') or be a full url.

Query arguments may also be specified for the request. Each query
argument, appearing after '--', taking the form
'--<query-arg>=<value>' will be added to the request. For example,
'rbt api-get /review-requests/ -- --counts-only=1' would result in
a request to 'http://example.com/api/review-requests/?counts-only=1'.

To support this new command, a new 'get_url' is now required for
transports. This change provides the required method for the
SyncTransport.
Requested a number of resources with different query arguments and
observed the expected JSON output. Also tested some error conditions
such as print the error payloads when requesting non-existent
review-request resources (ids which don't exist).
Description From Last Updated

"URL"

chipx86chipx86

"URL". Same with other instances of "url."

chipx86chipx86

Comma after ``https://`

chipx86chipx86

This is kind of worded strangely. Maybe: "Each query argument appears after ``--`` on the command line and takes the …

chipx86chipx86

Maybe define this example as its own indented block.

chipx86chipx86

Should be "rbt api-get"

chipx86chipx86

This is too specific to this command. Maybe we start doing something like: command_options = { 'api-get': { 'PRETTY_PRINT': True, …

chipx86chipx86

"Retrieve" "URL"

chipx86chipx86

"URL" Maybe "The URL is not guaranteed to be part of the configured Review Board domain."

chipx86chipx86

Should ideally use endswith() for readability.

chipx86chipx86

"Retrieve" Maybe "Retrieve raw API resource payloads."

chipx86chipx86

"Pretty" should be capitalized, like the others.

chipx86chipx86

No need for the if statement. args is guaranteed to be iterable.

chipx86chipx86

"retrieve"

chipx86chipx86

This is repeated twice. Let's just make a self._dumps function that does this.

chipx86chipx86
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        rbtools/api/client.py
        rbtools/api/resource.py
        rbtools/api/transport/__init__.py
        rbtools/commands/api_get.py
        rbtools/api/decode.py
        rbtools/api/transport/sync.py
        setup.py
      Ignored Files:
        docs/rbtools/rbt/commands/index.txt
        docs/rbtools/rbt/commands/api-get.txt
    
    
  2. 
      
chipx86
  1. 
      
  2. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    "URL"
  3. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    "URL".
    
    Same with other instances of "url."
  4. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    Comma after ``https://`
  5. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
     
     
    Show all issues
    This is kind of worded strangely. Maybe:
     "Each query argument appears after ``--`` on the command line and takes the form of ``--<query-arg>=<value>``."
    
    I don't think you need the last "will be added to the request," since that's implied by the previous sentence.
  6. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    Maybe define this example as its own indented block.
  7. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    Should be "rbt api-get"
  8. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Show all issues
    This is too specific to this command. Maybe we start doing something like:
    
    command_options = {
        'api-get': {
            'PRETTY_PRINT': True,
        }
    }
    
    Or if that's too Pythonic or troublesome, maybe just API_GET_PRETTY_PRINT. Not sure.
    1. I went with API_GET_PRETTY_PRINT.
      
      I'd rather keep things as flat as possible right now. I'm always wanting to move
      away from having .reviewboardrc files evaluated as code to deal with configuration
      and documenting more complex configuration like this might make things difficult if
      we try and make the jump at some point.
  9. rbtools/api/transport/__init__.py (Diff revision 1)
     
     
    Show all issues
    "Retrieve"
    
    "URL"
  10. rbtools/api/transport/__init__.py (Diff revision 1)
     
     
    Show all issues
    "URL"
    
    Maybe "The URL is not guaranteed to be part of the configured Review Board domain."
  11. rbtools/api/transport/sync.py (Diff revision 1)
     
     
    Show all issues
    Should ideally use endswith() for readability.
  12. rbtools/commands/api_get.py (Diff revision 1)
     
     
    Show all issues
    "Retrieve"
    
    Maybe "Retrieve raw API resource payloads."
  13. rbtools/commands/api_get.py (Diff revision 1)
     
     
    Show all issues
    "Pretty" should be capitalized, like the others.
  14. rbtools/commands/api_get.py (Diff revision 1)
     
     
     
    Show all issues
    No need for the if statement. args is guaranteed to be iterable.
    1. Ah, it was a leftover from when the args were used for a different purpose
      where behavior changed if there were any.
  15. rbtools/commands/api_get.py (Diff revision 1)
     
     
    Show all issues
    "retrieve"
    1. Wow, apparently I never spell this correctly. Sorry you had to be my spellcheck :/
  16. rbtools/commands/api_get.py (Diff revision 1)
     
     
     
     
     
    Show all issues
    This is repeated twice. Let's just make a self._dumps function that does this.
  17. 
      
SM
reviewbot
  1. This is a review from Review Bot.
      Tool: PEP8 Style Checker
      Processed Files:
        rbtools/api/client.py
        rbtools/api/resource.py
        rbtools/api/transport/__init__.py
        rbtools/commands/api_get.py
        rbtools/api/decode.py
        rbtools/api/transport/sync.py
        setup.py
      Ignored Files:
        docs/rbtools/rbt/commands/index.txt
        docs/rbtools/rbt/commands/api-get.txt
    
    
  2. 
      
chipx86
  1. Ship It!
  2. 
      
SM
Review request changed
Status:
Completed
Change Summary:
Pushed to master, release-0.5.x (fc01bea128a67c0f3a318a75ad47c425d844d8de).