Class: AlPapi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/al_papi/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Request

config
  • Hash { auth_key: ‘your_auth_token’ }

  • OR AlPapi::Config



12
13
14
15
# File 'lib/al_papi/request.rb', line 12

def initialize(config)
  @config  = config.is_a?(AlPapi::Config) ? config : Config.new(config)
  @success, @errors = false, []
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



5
6
7
# File 'lib/al_papi/request.rb', line 5

def config
  @config
end

Instance Method Details

#get(params = {}) ⇒ Object

Params

Parameters should be the same as what was posted to the Partner API where applies.

keyword

Required - The keyword you are ready to get results for.

engine

Optional - Defaults to google. Allowed engines are google, yahoo, bing.

locale

Optional - Defaults to en-us. See AlPapi::Locales for supported locales.

rank_date

Optional - Default is set to today UTC time. Date should be in format of YYYY-MM-DD ie. 2011-12-28

data_format

Optional - Default is JSON. Options are HTML or JSON.



69
70
71
# File 'lib/al_papi/request.rb', line 69

def get(params = {})
  http.get '/keywords/get', params
end

#httpObject



17
18
19
# File 'lib/al_papi/request.rb', line 17

def http # @private
  Http.new(@config)
end

#post(params = {}, priority = false) ⇒ Object

Params

keyword

Required - Your keyword you want to get results for

engine

Optional - Defaults to google. Allowed engines are google, yahoo, bing.

locale

Optional - Defaults to en-us. See AlPapi::Locales for supported locales.

pages_from

Optional - Default is false. Google specific parameter to get results from the locale passed in when set to true.

callback

Optional - Default is set on your account through the website. Set specific callbacks here for each request. Callback a url that is sent a POST when results are returned.



38
39
40
41
# File 'lib/al_papi/request.rb', line 38

def post(params = {}, priority = false)
  path = priority ? '/keywords/priority' : '/keywords'
  http.post path, params
end

#priority_post(params = {}) ⇒ Object

Params

See post for required params



48
49
50
# File 'lib/al_papi/request.rb', line 48

def priority_post(params = {})
  post params, true
end