Class: Yelp::Client
- Inherits:
-
Object
- Object
- Yelp::Client
- Defined in:
- lib/yelp/client.rb
Constant Summary collapse
- API_HOST =
'https://api.yelp.com'
- REQUEST_CLASSES =
[ Yelp::Endpoint::Search, Yelp::Endpoint::Business, Yelp::Endpoint::PhoneSearch]
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
-
#check_api_keys ⇒ Object
Checks that all the keys needed were given.
-
#configure {|Configuration| ... } ⇒ Object
Configure the API client.
-
#connection ⇒ Object
API connection.
-
#initialize(options = nil) ⇒ Client
constructor
Creates an instance of the Yelp client.
Constructor Details
#initialize(options = nil) ⇒ Client
Creates an instance of the Yelp client
23 24 25 26 27 28 29 30 31 |
# File 'lib/yelp/client.rb', line 23 def initialize( = nil) @configuration = nil define_request_methods unless .nil? @configuration = Configuration.new() check_api_keys end end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
17 18 19 |
# File 'lib/yelp/client.rb', line 17 def configuration @configuration end |
Instance Method Details
#check_api_keys ⇒ Object
Checks that all the keys needed were given
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/yelp/client.rb', line 52 def check_api_keys if configuration.nil? || !configuration.valid? @configuration = nil raise Error::MissingAPIKeys else # Freeze the configuration so it cannot be modified once the gem is # configured. This prevents the configuration changing while the gem # is operating, which would necessitate invalidating various caches. @configuration.freeze end end |
#configure {|Configuration| ... } ⇒ Object
Configure the API client
43 44 45 46 47 48 49 |
# File 'lib/yelp/client.rb', line 43 def configure raise Error::AlreadyConfigured unless @configuration.nil? @configuration = Configuration.new yield(@configuration) check_api_keys end |
#connection ⇒ Object
API connection
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/yelp/client.rb', line 65 def connection return @connection if instance_variable_defined?(:@connection) check_api_keys @connection = Faraday.new(API_HOST) do |conn| # Use the Faraday OAuth middleware for OAuth 1.0 requests conn.request :oauth, @configuration.auth_keys # Using default http library, had to specify to get working conn.adapter :net_http end end |