Class: EDH::Passport::API
- Inherits:
-
Object
- Object
- EDH::Passport::API
- Includes:
- RestAPIMethods
- Defined in:
- lib/edh/api.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
Instance Method Summary collapse
-
#api(path, args = {}, verb = "get", options = {}, &error_checking_block) { ... } ⇒ Object
Makes a request to the appropriate Passport API.
-
#initialize(options = {}) ⇒ EDH::Passport::API
constructor
Creates a new API client.
Methods included from RestAPIMethods
#create, #delete, #rest_call, #update
Constructor Details
#initialize(options = {}) ⇒ EDH::Passport::API
Note:
If no access token is provided, you can only access some public information.
Creates a new API client.
11 12 13 14 15 |
# File 'lib/edh/api.rb', line 11 def initialize = {} @access_token = [:access_token] @app_access_token = [:app_token] @server = [:server] end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
17 18 19 |
# File 'lib/edh/api.rb', line 17 def access_token @access_token end |
Instance Method Details
#api(path, args = {}, verb = "get", options = {}, &error_checking_block) { ... } ⇒ Object
Note:
You’ll rarely need to call this method directly.
Makes a request to the appropriate Passport API.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/edh/api.rb', line 40 def api(path, args = {}, verb = "get", = {}, &error_checking_block) # If a access token is explicitly provided, use that # This is explicitly needed in batch requests so GraphCollection # results preserve any specific access tokens provided args["access_token"] ||= @access_token || @app_access_token if @access_token || @app_access_token .merge!({:server => @server}) unless @server.nil? # Translate any arrays in the params into comma-separated strings args = sanitize_request_parameters(args) # add a leading / path = "/#{path}" unless path =~ /^\// # make the request via the provided service result = EDH.make_request(path, args, verb, ) if result.status.to_i >= 500 raise EDH::Passport::ServerError.new(result.status.to_i, result.body) end yield result if error_checking_block # if we want a component other than the body (e.g. redirect header for images), return that if component = [:http_component] component == :response ? result : result.send([:http_component]) else # parse the body as JSON and run it through the error checker (if provided) # Note: Passport sometimes sends results like "true" and "false", which aren't strictly objects # and cause MultiJson.load to fail -- so we account for that by wrapping the result in [] MultiJson.load("[#{result.body.to_s}]")[0] end end |