Class: Bing::Content::Api::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bing/content/api/client.rb

Constant Summary collapse

REDIRECT_URI =
"https://login.live.com/oauth20_desktop.srf".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, developer_token, merchant_id, refresh_token = nil, catalogue_id = nil) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
# File 'lib/bing/content/api/client.rb', line 13

def initialize(client_id, developer_token, merchant_id, refresh_token=nil, catalogue_id=nil)
  @client_id = client_id
  @developer_token = developer_token
  @merchant_id = merchant_id
  @refresh_token = refresh_token
  @catalogue_id = catalogue_id
  @token = nil
  @refresh_token_callback = nil
end

Instance Attribute Details

#developer_tokenObject (readonly)

Returns the value of attribute developer_token.



9
10
11
# File 'lib/bing/content/api/client.rb', line 9

def developer_token
  @developer_token
end

#refresh_tokenObject

Returns the value of attribute refresh_token.



8
9
10
# File 'lib/bing/content/api/client.rb', line 8

def refresh_token
  @refresh_token
end

#refresh_token_callbackObject

Returns the value of attribute refresh_token_callback.



7
8
9
# File 'lib/bing/content/api/client.rb', line 7

def refresh_token_callback
  @refresh_token_callback
end

Instance Method Details

#fetch_token_with_code!(verified_url) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/bing/content/api/client.rb', line 29

def fetch_token_with_code!(verified_url)
  @token = oauth_client.auth_code.get_token(
    extract_code(verified_url),
    :redirect_uri => REDIRECT_URI
  )
  self.refresh_token = @token.refresh_token
end

#generate_user_authorisation_urlObject



23
24
25
26
27
# File 'lib/bing/content/api/client.rb', line 23

def generate_user_authorisation_url
  oauth_client.auth_code.authorize_url(
    :state => "ArizonaIsAState",
    :scope => "bingads.manage")
end

#retrieve_catalogueObject



42
43
44
45
# File 'lib/bing/content/api/client.rb', line 42

def retrieve_catalogue
  response = connector.get('/products')
  JSON.parse(response.body)["resources"]
end

#run_batch(batch) ⇒ Object



37
38
39
40
# File 'lib/bing/content/api/client.rb', line 37

def run_batch(batch)
  batch_processor = Bing::Content::Api::BatchProcessor.new(connector)
  batch_processor.execute(batch)
end