Class: Bing::Content::Api::Client
- Inherits:
-
Object
- Object
- Bing::Content::Api::Client
- 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
-
#developer_token ⇒ Object
readonly
Returns the value of attribute developer_token.
-
#refresh_token ⇒ Object
readonly
Returns the value of attribute refresh_token.
-
#refresh_token_callback ⇒ Object
Returns the value of attribute refresh_token_callback.
Instance Method Summary collapse
- #connector ⇒ Object
- #fetch_token_with_code!(verified_url) ⇒ Object
- #generate_user_authorisation_url ⇒ Object
-
#initialize(client_id, developer_token, merchant_id, refresh_token = nil, catalogue_id = nil) ⇒ Client
constructor
A new instance of Client.
- #retrieve_catalogue ⇒ Object
- #run_batch(batch) ⇒ Object
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_token ⇒ Object (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_token ⇒ Object
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_callback ⇒ Object
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
#connector ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/bing/content/api/client.rb', line 48 def connector refresh_token! unless @connector @connector ||= Bing::Content::Api::Connector.new(@developer_token, @token.token, @merchant_id, @catalogue_id) end |
#fetch_token_with_code!(verified_url) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/bing/content/api/client.rb', line 30 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_url ⇒ Object
23 24 25 26 27 28 |
# File 'lib/bing/content/api/client.rb', line 23 def oauth_client.auth_code.( state: "ArizonaIsAState", scope: "bingads.manage" ) end |
#retrieve_catalogue ⇒ Object
43 44 45 46 |
# File 'lib/bing/content/api/client.rb', line 43 def retrieve_catalogue response = connector.get('/products') JSON.parse(response.body)["resources"] end |
#run_batch(batch) ⇒ Object
38 39 40 41 |
# File 'lib/bing/content/api/client.rb', line 38 def run_batch(batch) batch_processor = Bing::Content::Api::BatchProcessor.new(connector) batch_processor.execute(batch) end |