Module: RGData::API::ClassMethods

Defined in:
lib/rgdata/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject

Returns the value of attribute model.



15
16
17
# File 'lib/rgdata/api.rb', line 15

def model
  @model
end

#scopeObject

Returns the value of attribute scope.



14
15
16
# File 'lib/rgdata/api.rb', line 14

def scope
  @scope
end

Instance Method Details

#do_request(domain, options) ⇒ Object

Send request for data (not authentication) and return response. options can be :oauth_token, :access_token, or :refresh_token.



23
24
25
26
27
28
29
30
31
# File 'lib/rgdata/api.rb', line 23

def do_request(domain, options)
  oauth_token = extract_oauth_token_or_access_token_or_get_one_using_refresh_token(options)
  query = {
    oauth_token: oauth_token,
  }
  query.verify_keys_present_and_values_not_blank(:oauth_token)
  raise 'Domain cannot be blank' if domain.blank?
  get "/#{domain}/full", query: query
end

#request_url(redirect_uri) ⇒ Object



17
18
19
# File 'lib/rgdata/api.rb', line 17

def request_url(redirect_uri)
  RGData::Authentication.request_url(scope, redirect_uri)
end

#retrieve(domain, options) ⇒ Object

Perform request and create new model objects. See do_request() for arguments info.



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rgdata/api.rb', line 35

def retrieve(domain, options)
  raise 'domain cannot be nil' unless domain
  full_xml_hash = do_request(domain, options)
  full_xml_hash['feed']['entry'].map do |xml_hash|
    model.new_from_xml_hash xml_hash
  end
rescue
  puts 'Unexpected response:'
  puts full_xml_hash
  raise
end