Introduce the api-get command.

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

smacleod
RBTools
master
rbtools
chipx86, mw_triad
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)
     
     
    "URL".
    
    Same with other instances of "url."
  3. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Comma after ``https://`
  4. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
     
     
    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.
  5. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Maybe define this example as its own indented block.
  6. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    Should be "rbt api-get"
  7. docs/rbtools/rbt/commands/api-get.txt (Diff revision 1)
     
     
    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.
  8. rbtools/api/transport/__init__.py (Diff revision 1)
     
     
    "Retrieve"
    
    "URL"
  9. rbtools/api/transport/__init__.py (Diff revision 1)
     
     
    "URL"
    
    Maybe "The URL is not guaranteed to be part of the configured Review Board domain."
  10. rbtools/api/transport/sync.py (Diff revision 1)
     
     
    Should ideally use endswith() for readability.
  11. rbtools/commands/api_get.py (Diff revision 1)
     
     
    "Retrieve"
    
    Maybe "Retrieve raw API resource payloads."
  12. rbtools/commands/api_get.py (Diff revision 1)
     
     
    "Pretty" should be capitalized, like the others.
  13. rbtools/commands/api_get.py (Diff revision 1)
     
     
     
    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.
  14. rbtools/commands/api_get.py (Diff revision 1)
     
     
    "retrieve"
    1. Wow, apparently I never spell this correctly. Sorry you had to be my spellcheck :/
  15. rbtools/commands/api_get.py (Diff revision 1)
     
     
     
     
     
    This is repeated twice. Let's just make a self._dumps function that does this.
  16. 
      
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: Closed (submitted)

Change Summary:

Pushed to master, release-0.5.x (fc01bea128a67c0f3a318a75ad47c425d844d8de).
Loading...