Class: NRB::Untappd::API
- Inherits:
-
Object
- Object
- NRB::Untappd::API
- Defined in:
- lib/drink-socially/api.rb,
lib/drink-socially/api/object.rb,
lib/drink-socially/api/credential.rb,
lib/drink-socially/api/pagination.rb,
lib/drink-socially/api/rate_limit.rb,
lib/drink-socially/api/notification.rb,
lib/drink-socially/api/url_tokenizer.rb
Defined Under Namespace
Classes: Credential, Notification, Object, Pagination, RateLimit, URLTokenizer
Constant Summary collapse
- API_VERSION =
Use NRB::Untappd::API.api_version instead
:v4
- SERVER =
Use NRB::Untappd::API.server instead
'api.untappd.com'
Instance Attribute Summary collapse
-
#credential ⇒ Object
readonly
Returns the value of attribute credential.
-
#endpoints ⇒ Object
readonly
Returns the value of attribute endpoints.
-
#rate_limit ⇒ Object
readonly
Returns the value of attribute rate_limit.
Class Method Summary collapse
- .api_version ⇒ Object
- .default_rate_limit_class ⇒ Object
- .default_response_class ⇒ Object
- .requestor ⇒ Object
- .server ⇒ Object
Instance Method Summary collapse
-
#add_checkin(args) ⇒ Object
untappd.com/api/docs/v4#checkin Required args: bid.
- #api_call(args) ⇒ Object
-
#initialize(args = {}) ⇒ API
constructor
A new instance of API.
Constructor Details
#initialize(args = {}) ⇒ API
Returns a new instance of API.
56 57 58 59 60 61 |
# File 'lib/drink-socially/api.rb', line 56 def initialize(args={}) @api_version = args[:api_version] || self.class.api_version @credential = args[:credential] || Credential.new(args.dup) @server = args[:server] || self.class.server define_endpoints_from(args) end |
Instance Attribute Details
#credential ⇒ Object (readonly)
Returns the value of attribute credential.
14 15 16 |
# File 'lib/drink-socially/api.rb', line 14 def credential @credential end |
#endpoints ⇒ Object (readonly)
Returns the value of attribute endpoints.
14 15 16 |
# File 'lib/drink-socially/api.rb', line 14 def endpoints @endpoints end |
#rate_limit ⇒ Object (readonly)
Returns the value of attribute rate_limit.
14 15 16 |
# File 'lib/drink-socially/api.rb', line 14 def rate_limit @rate_limit end |
Class Method Details
.api_version ⇒ Object
16 |
# File 'lib/drink-socially/api.rb', line 16 def self.api_version; API_VERSION; end |
.default_rate_limit_class ⇒ Object
17 |
# File 'lib/drink-socially/api.rb', line 17 def self.default_rate_limit_class; RateLimit; end |
.default_response_class ⇒ Object
18 |
# File 'lib/drink-socially/api.rb', line 18 def self.default_response_class; Object; end |
Instance Method Details
#add_checkin(args) ⇒ Object
untappd.com/api/docs/v4#checkin Required args: bid
25 26 27 28 29 30 31 32 33 |
# File 'lib/drink-socially/api.rb', line 25 def add_checkin(args) validate_api_args args, :bid t = Time.now args[:endpoint] = 'checkin/add' args[:gmt_offset] ||= t.gmt_offset / 3600 args[:timezone] ||= t.zone args[:verb] = :post api_call args end |
#api_call(args) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/drink-socially/api.rb', line 36 def api_call(args) endpoint = args.delete(:endpoint) config = get_config endpoint return unless config validate_api_args args, *config[:required_args] args.merge!(config) args[:response_class] ||= self.class.default_response_class tokenizer = URLTokenizer.new map: args, string: args.delete(:endpoint) args[:url] = find_path_at tokenizer.tr response = self.class.requestor.make_request(args) @rate_limit = self.class.default_rate_limit_class.new(response.headers) response end |