Module: HeroixApi
- Defined in:
- lib/heroix_api/data.rb,
lib/heroix_api.rb,
lib/heroix_api/processor.rb
Overview
HeroixApi::Data
Encapsulates data from the HeroixApi in an easy to use form. This does not care about the data type too much and just returns it as an open struct. TODO: less abstracted data types.
Defined Under Namespace
Class Attribute Summary collapse
-
.api_key ⇒ Object
Returns the value of attribute api_key.
-
.login ⇒ Object
Returns the value of attribute login.
-
.root_url ⇒ Object
Returns the value of attribute root_url.
-
.ssl ⇒ Object
Returns the value of attribute ssl.
-
.timeout ⇒ Object
Returns the value of attribute timeout.
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Configure Heroix Api.
-
.get_resource(path, params = {}) ⇒ Object
Make an API call to get a resource from the server.
-
.log_error(error) ⇒ Object
Log errors.
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/heroix_api.rb', line 7 def api_key @api_key end |
.login ⇒ Object
Returns the value of attribute login.
7 8 9 |
# File 'lib/heroix_api.rb', line 7 def login @login end |
.root_url ⇒ Object
Returns the value of attribute root_url.
7 8 9 |
# File 'lib/heroix_api.rb', line 7 def root_url @root_url end |
.ssl ⇒ Object
Returns the value of attribute ssl.
7 8 9 |
# File 'lib/heroix_api.rb', line 7 def ssl @ssl end |
.timeout ⇒ Object
Returns the value of attribute timeout.
7 8 9 |
# File 'lib/heroix_api.rb', line 7 def timeout @timeout end |
Class Method Details
.configure {|_self| ... } ⇒ Object
Configure Heroix Api.
HeroixApi.configure do |config|
config.api_key = "AAAAAABBBBBCCCCC1111122222"
config.login = "user_name"
config.root_url = "https://heroix.everydayhero.com.au/api/v1/"
end
Configurable settings
- api_key = String
-
Your Heroix API key
- login = String
-
Your Heroix API login
- root_url = String
-
The url to the Heroix api host. Defaults to the current production API host.
- timeout = Integer
-
The time in seconds to wait for the server to respond before raising a timeout error.
25 26 27 |
# File 'lib/heroix_api.rb', line 25 def configure yield self end |
.get_resource(path, params = {}) ⇒ Object
Make an API call to get a resource from the server
- path
-
The resource to get.
- query_string
-
The query string to pass with the request.
Example calls:
@campaign = HeroixApi.get_resource("campaigns/2.json")
@hero_pages = HeroixApi.get_resource('hero_pages.json', {active => true})
Returns a HeroixApi::Data object The data is accessible via the data member on this object. It also provides meta_data for the object, primarily the pagination links.
52 53 54 55 56 57 58 |
# File 'lib/heroix_api.rb', line 52 def get_resource(path, params = {}) query = params.map do |key, value| "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" end.join '&' query = "?#{query}" unless query.blank? api_data = HeroixApi::Processor.get_api_response("#{path}#{query}") end |
.log_error(error) ⇒ Object
Log errors
Override this method to provide your own error logging By default just prints errors to STDERR
34 35 36 |
# File 'lib/heroix_api.rb', line 34 def log_error error printf $stderr, error end |