Class: IfreeSms::API
- Inherits:
-
Object
- Object
- IfreeSms::API
- Defined in:
- lib/ifree_sms.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
Instance Method Summary collapse
- #api(path, args = {}, verb = "get", options = {}) {|body| ... } ⇒ Object
-
#initialize(login = nil, pass = nil) ⇒ API
constructor
initialize with an access token.
Constructor Details
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
23 24 25 |
# File 'lib/ifree_sms.rb', line 23 def access_token @access_token end |
Instance Method Details
#api(path, args = {}, verb = "get", options = {}) {|body| ... } ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ifree_sms.rb', line 25 def api(path, args = {}, verb = "get", = {}, &error_checking_block) # Fetches the given path in the Graph API. args["login"] = @login args["pass"] = @pass # add a leading / path = "/#{path}" unless path =~ /^(\/|http|https|ftp)/ # make the request via the provided service result = IfreeSms.make_request(path, args, verb, ) # Check for any 500 errors before parsing the body # since we're not guaranteed that the body is valid JSON # in the case of a server error raise APIError.new({"type"=>"HTTP #{result.status.to_s}", "message"=>"Response body: #{result.body}"}) if result.status >= 500 body = result.body yield body if error_checking_block # if we want a component other than the body (e.g. redirect header for images), return that [:http_component] ? result.send([:http_component]) : body end |