Class: RubyMeetup::Client
- Inherits:
-
Object
- Object
- RubyMeetup::Client
- Defined in:
- lib/ruby_meetup.rb
Overview
This class is abstract. It has accessor methods for configuring the API site. By default it is set to api.meetup.com but may be changed using the class setter method site=
.
The gem supports API request with two authentication strategies: API Key and OAuth 2 via the concrete classes ApiKeyClient and AuthenticatedClient, respectively. More information can be found in the specific class documentation.
Example usage:
> require 'ruby_meetup'
> RubyMeetup::ApiKeyClient.key = 'abcd000000000000000wxyz'
> client = RubyMeetup::ApiKeyClient.new
> json_string = client.get_path("/2/groups", {:group_id => 390230})
> second_result = client.get({:group_id => 939203})
If successful the captured response is a raw JSON string. The response can then be processed using a JSON parser. Otherwise an exception is raised.
Typically, ApiKeyClient class is used to read data while the AuthenticatedClient class is used for both read and write data, subject to Meetup API permission scopes.
Copyright © 2013 Long On, released under the MIT license
Direct Known Subclasses
Constant Summary collapse
- @@site =
"https://api.meetup.com"
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
-
.site ⇒ Object
Retun the configured API endpoint.
-
.site=(string) ⇒ Object
Set the global API endpoint.
Instance Method Summary collapse
-
#get(options = {}) ⇒ Object
Make a GET API call with the current path value and @options.
-
#get_path(path, options = {}) ⇒ Object
A convenience method to set @path and @options in the same API call.
-
#to_s ⇒ Object
:nodoc:.
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
39 40 41 |
# File 'lib/ruby_meetup.rb', line 39 def path @path end |
Class Method Details
.site ⇒ Object
Retun the configured API endpoint
44 45 46 |
# File 'lib/ruby_meetup.rb', line 44 def self.site @@site end |
.site=(string) ⇒ Object
Set the global API endpoint
48 49 50 |
# File 'lib/ruby_meetup.rb', line 48 def self.site=string @@site = string end |
Instance Method Details
#get(options = {}) ⇒ Object
Make a GET API call with the current path value and @options. Return a JSON string if successful, otherwise an Exception
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby_meetup.rb', line 63 def get(={}) uri = new_uri params = merge_params() uri.query = URI.encode_www_form(params) Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| request = Net::HTTP::Get.new(uri) response = http.request(request) unless response.is_a?(Net::HTTPSuccess) raise "#{response.code} #{response.}\n#{response.body}" end return response.body end end |
#get_path(path, options = {}) ⇒ Object
A convenience method to set @path and @options in the same API call. Return a JSON string if successful, otherwise an Exception
56 57 58 59 |
# File 'lib/ruby_meetup.rb', line 56 def get_path(path, ={}) self.path = path get() end |
#to_s ⇒ Object
:nodoc:
79 80 81 |
# File 'lib/ruby_meetup.rb', line 79 def to_s "#{self.class.name}: site=#{@@site}, path=#{path}" end |