class NikeV2::Resource

Constants

RESP_MSG_INVALID_TOKEN

Public Class Methods

new(attributes={}) click to toggle source
Calls superclass method NikeV2::Base::new
# File lib/nike_v2/resource.rb, line 16
def initialize(attributes={})
  super(attributes)
end

Public Instance Methods

fetch_data(*args) click to toggle source
# File lib/nike_v2/resource.rb, line 20
def fetch_data(*args)
  args.unshift(api_url)
  resp = get(*args).parsed_response.clone

  if !resp['error'].nil? && resp['error'] == RESP_MSG_INVALID_TOKEN
    raise "#{self.class} invalid or expired token, can not fetch data from server."   
  end
  resp
end
get(*args, &block) click to toggle source
# File lib/nike_v2/resource.rb, line 30
def get(*args, &block)
  build_options(args)
  self.class.send(get_method, *args, &block)
end

Private Instance Methods

api_url() click to toggle source
# File lib/nike_v2/resource.rb, line 57
def api_url
  self.class.const_get('API_URL')
end
app_id() click to toggle source
# File lib/nike_v2/resource.rb, line 48
def app_id
  #TODO: make this a config yaml
  'nike'
end
build_options(args) click to toggle source
# File lib/nike_v2/resource.rb, line 37
def build_options(args)
  query = has_options?(args) ? args.pop : {}

  query.merge!('access_token' => access_token)
  headers = { 'Accept' => 'application/json', 'appid' => app_id }
  options = { query: query, headers: headers }

  args << options
end
get_method() click to toggle source
# File lib/nike_v2/resource.rb, line 61
def get_method
  if NikeV2.configuration.cache
    'get_with_caching'
  else
    'get'
  end
end
has_options?(args) click to toggle source
# File lib/nike_v2/resource.rb, line 53
def has_options?(args)
  args.last.is_a?(Hash)
end