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

Classes: Data, Processor

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



7
8
9
# File 'lib/heroix_api.rb', line 7

def api_key
  @api_key
end

.loginObject

Returns the value of attribute login.



7
8
9
# File 'lib/heroix_api.rb', line 7

def 
  @login
end

.root_urlObject

Returns the value of attribute root_url.



7
8
9
# File 'lib/heroix_api.rb', line 7

def root_url
  @root_url
end

.sslObject

Returns the value of attribute ssl.



7
8
9
# File 'lib/heroix_api.rb', line 7

def ssl
  @ssl
end

.timeoutObject

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. = "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.

Yields:

  • (_self)

Yield Parameters:

  • _self (HeroixApi)

    the object that the method was called on



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