Class: YahooGeminiClient::Client
- Inherits:
-
Object
- Object
- YahooGeminiClient::Client
- Defined in:
- lib/yahoo_gemini_client/client.rb
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#oauth2_client ⇒ Object
Returns the value of attribute oauth2_client.
Instance Method Summary collapse
- #ad_groups ⇒ Object
- #advertisers ⇒ Object
- #api_request_headers ⇒ Object
- #authorization_url ⇒ Object
- #campaigns ⇒ Object
- #custom_report ⇒ Object
- #encoded_creds ⇒ Object
- #get_token(authorization_code) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #oauth2_headers ⇒ Object
- #token_refresh! ⇒ Object
- #user_agent ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/yahoo_gemini_client/client.rb', line 12 def initialize(={}) @consumer_key = [:consumer_key] @consumer_secret = [:consumer_secret] @oauth2_client ||= OAuth2::Client.new(consumer_key, consumer_secret, { :site => 'https://api.login.yahoo.com', :authorize_url => '/oauth2/request_auth', :token_url => '/oauth2/get_token', }) @refresh_token = [:refresh_token] @token = OAuth2::AccessToken.from_hash( @oauth2_client, refresh_token: @refresh_token, ) end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
5 6 7 |
# File 'lib/yahoo_gemini_client/client.rb', line 5 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
5 6 7 |
# File 'lib/yahoo_gemini_client/client.rb', line 5 def consumer_secret @consumer_secret end |
#oauth2_client ⇒ Object
Returns the value of attribute oauth2_client.
5 6 7 |
# File 'lib/yahoo_gemini_client/client.rb', line 5 def oauth2_client @oauth2_client end |
Instance Method Details
#ad_groups ⇒ Object
85 86 87 |
# File 'lib/yahoo_gemini_client/client.rb', line 85 def ad_groups AdGroups.new(client: self) end |
#advertisers ⇒ Object
65 66 67 |
# File 'lib/yahoo_gemini_client/client.rb', line 65 def advertisers Advertisers.new(client: self) end |
#api_request_headers ⇒ Object
54 55 56 57 58 59 |
# File 'lib/yahoo_gemini_client/client.rb', line 54 def api_request_headers { "Authorization" => "Bearer #{token.token}", "User-Agent" => user_agent, } end |
#authorization_url ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/yahoo_gemini_client/client.rb', line 27 def oauth2_client.auth_code.( :redirect_uri => "oob", :response_type => "code", :language => "en-us", ) end |
#campaigns ⇒ Object
69 70 71 |
# File 'lib/yahoo_gemini_client/client.rb', line 69 def campaigns Campaigns.new(client: self) end |
#custom_report ⇒ Object
73 74 75 |
# File 'lib/yahoo_gemini_client/client.rb', line 73 def custom_report CustomReport.new(client: self) end |
#encoded_creds ⇒ Object
35 36 37 |
# File 'lib/yahoo_gemini_client/client.rb', line 35 def encoded_creds Base64.encode64("#{consumer_key}:#{consumer_secret}").gsub(/\n/,"").strip end |
#get_token(authorization_code) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/yahoo_gemini_client/client.rb', line 39 def get_token() self.token = oauth2_client.auth_code.get_token(, { :redirect_uri => 'oob', :headers => oauth2_headers, }) end |
#oauth2_headers ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/yahoo_gemini_client/client.rb', line 46 def oauth2_headers { 'Authorization' => "Basic #{encoded_creds}", 'Content-Type' => 'application/x-www-form-urlencoded', 'User-Agent' => user_agent, } end |
#token_refresh! ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/yahoo_gemini_client/client.rb', line 77 def token_refresh! # TODO: handle when there's no token self.token = self.token.refresh!({ :redirect_uri => 'oob', :headers => oauth2_headers }) end |
#user_agent ⇒ Object
61 62 63 |
# File 'lib/yahoo_gemini_client/client.rb', line 61 def user_agent @user_agent ||= "YahooGeminiClientRubyGem/#{YahooGeminiClient::VERSION}" end |