Class: KeywordsEverywhere::Client
- Inherits:
-
Object
- Object
- KeywordsEverywhere::Client
- Defined in:
- lib/keywords_everywhere/client.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#market ⇒ Object
Returns the value of attribute market.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#secret_key ⇒ Object
readonly
Returns the value of attribute secret_key.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #credits ⇒ Object
-
#initialize(secret_key: KeywordsEverywhere.secret_key || ENV['KW_SECRET'], market: KeywordsEverywhere.market || DEFAULT_MARKET, source: KeywordsEverywhere.source || DEFAULT_SOURCE, currency: KeywordsEverywhere.currency || DEFAULT_CURRENCY) ⇒ Client
constructor
A new instance of Client.
- #list ⇒ Object
- #search_items(keywords) ⇒ Object
- #time ⇒ Object
- #to_items ⇒ Object
Constructor Details
#initialize(secret_key: KeywordsEverywhere.secret_key || ENV['KW_SECRET'], market: KeywordsEverywhere.market || DEFAULT_MARKET, source: KeywordsEverywhere.source || DEFAULT_SOURCE, currency: KeywordsEverywhere.currency || DEFAULT_CURRENCY) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/keywords_everywhere/client.rb', line 8 def initialize( secret_key: KeywordsEverywhere.secret_key || ENV['KW_SECRET'], market: KeywordsEverywhere.market || DEFAULT_MARKET, source: KeywordsEverywhere.source || DEFAULT_SOURCE, currency: KeywordsEverywhere.currency || DEFAULT_CURRENCY ) @source = source.to_s.downcase @secret_key = secret_key @market = market.to_s.downcase @currency = currency.to_s.downcase end |
Instance Attribute Details
#currency ⇒ Object
Returns the value of attribute currency.
5 6 7 |
# File 'lib/keywords_everywhere/client.rb', line 5 def currency @currency end |
#market ⇒ Object
Returns the value of attribute market.
5 6 7 |
# File 'lib/keywords_everywhere/client.rb', line 5 def market @market end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/keywords_everywhere/client.rb', line 6 def response @response end |
#secret_key ⇒ Object (readonly)
Returns the value of attribute secret_key.
6 7 8 |
# File 'lib/keywords_everywhere/client.rb', line 6 def secret_key @secret_key end |
#source ⇒ Object
Returns the value of attribute source.
5 6 7 |
# File 'lib/keywords_everywhere/client.rb', line 5 def source @source end |
Instance Method Details
#credits ⇒ Object
36 37 38 |
# File 'lib/keywords_everywhere/client.rb', line 36 def credits response.dig('credits') end |
#list ⇒ Object
44 45 46 |
# File 'lib/keywords_everywhere/client.rb', line 44 def list List.new(response.dig('data')) end |
#search_items(keywords) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/keywords_everywhere/client.rb', line 22 def search_items(keywords) if keywords.is_a?(String) keywords = [keywords] end raise StandardError, "Keyword Up to 100" if keywords.size > 100 # https://api.keywordseverywhere.com/docs/#/keywords/get_keywords_data client = rest_client( method: :post, url: "https://api.keywordseverywhere.com/v1/get_keyword_data", payload: payload( kw: keywords ), headers: headers ) @response = JSON.parse(client.body) to_items end |
#time ⇒ Object
40 41 42 |
# File 'lib/keywords_everywhere/client.rb', line 40 def time response.dig('time') end |
#to_items ⇒ Object
48 49 50 |
# File 'lib/keywords_everywhere/client.rb', line 48 def to_items list.to_items end |