ruby_meetup2 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3b2259f6d227fabfd45a391f60fb921bfe5a9bfa
4
+ data.tar.gz: 261c71c7d833d3972848bea212a5e26dea6d6f24
5
+ SHA512:
6
+ metadata.gz: ad17c9b2e18a6f64ffbecf3a0a714cfedf6bec7b97b44d871f4e07f3ae0a268d63e71559efa132aec2042d35c523ed9d03bd7962d54677f3605ed31b6994825f
7
+ data.tar.gz: 0c25063711c7a25582a059c58872f42d12c69ae1953394f92287bee6594e89102fcc4fdb1d315905891498ef94b7145f72025c0d70295b22ebd8f6212255adca
@@ -0,0 +1,57 @@
1
+ module RubyMeetup
2
+
3
+ # This class is typically used to read data without needing to first obtain a
4
+ # user authenticated +access_token+. We just need a valid API Key, which any one
5
+ # can obtain directly from http://www.meetup.com
6
+ #
7
+ # The API key can be configured globally like so,
8
+ #
9
+ # > RubyMeetup::ApiKeyClient.key = 'abcd000000000000000wxyz'
10
+ #
11
+ # Then create a new client and make a request,
12
+ #
13
+ # > client = RubyMeetup::ApiKeyClient.new
14
+ # > json_string = client.get_path("/2/groups", {:group_id => 390230})
15
+ #
16
+ # The same client instance may be used to make multiple requests. Just supply a
17
+ # different @path and/or @options parameters as required.
18
+ #
19
+ # ---
20
+ # Copyright (c) 2013 Long On, released under the MIT license
21
+
22
+ class ApiKeyClient < Client
23
+ @@key = ""
24
+
25
+ # == class methods
26
+
27
+ # Set the global API Key
28
+ def self.key=string
29
+ @@key = string
30
+ end
31
+
32
+ # == instance methods
33
+
34
+ # :nodoc:
35
+ def to_s
36
+ s = super
37
+ s << ", key=#{short_key}"
38
+ end
39
+
40
+
41
+ protected
42
+ # :nodoc:
43
+ def merge_params(options)
44
+ {:sign => true, :key => @@key}.merge!(options)
45
+ end
46
+
47
+ # :nodoc:
48
+ def short_key
49
+ key = @@key
50
+ return "" if key.nil? || key.empty?
51
+ key[0..3] + "..." + key[(key.length - 4)..(key.length - 1)]
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,93 @@
1
+ module RubyMeetup
2
+
3
+ # This class can be used to read and write data on behalf of an authenticated user.
4
+ # An <b>OAuth 2</b> +access_token+ is given once user is authenticated. One of the
5
+ # methods is to use the +ominauth-meetup+ gem.
6
+ #
7
+ # An +access_token+ is user-specific so we configure it per Client instance like so,
8
+ #
9
+ # > client = RubyMeetup::AuthenticatedClient.new
10
+ # > client.access_token = user.access_token
11
+ #
12
+ # Then make a request,
13
+ #
14
+ # > json_string = client.get_path("/2/groups", {:member_id => user.member_id})
15
+ #
16
+ # The same client instance may be used to make multiple requests. Just supply a
17
+ # different @path and/or @options parameters as required.
18
+ #
19
+ # ---
20
+ # Copyright (c) 2013 Long On, released under the MIT license
21
+
22
+ class AuthenticatedClient < Client
23
+
24
+ attr_accessor :access_token
25
+
26
+ # == instance methods
27
+
28
+ # Make a POST API call with the current path value and @options.
29
+ # Return a JSON string if successful, otherwise an Exception
30
+ # TODO - test AuthenticatedClient.post()
31
+ def post(options)
32
+ uri = new_uri
33
+ params = merge_params(options)
34
+ response = Net::HTTP.post_form(uri, params)
35
+ unless response.is_a?(Net::HTTPSuccess)
36
+ raise "#{response.code} #{response.message}\n#{response.body}"
37
+ end
38
+ response.body
39
+ end
40
+
41
+ # Fake a PUT API call since meetup.com only support POST method
42
+ # TODO - test AuthenticatedClient.put()
43
+ def put(options)
44
+ post(options)
45
+ end
46
+
47
+ # Make a DELETE API call with the current path value and @options.
48
+ # Return true if successful, otherwise an Exception
49
+ # TODO - test AuthenticatedClient.delete()
50
+ def delete(options={})
51
+ uri = new_uri
52
+ params = merge_params(options)
53
+ uri.query = URI.encode_www_form(params)
54
+
55
+ http = Net::HTTP.new(uri.host, uri.port)
56
+ request = Net::HTTP::Delete.new(uri) # uri or uri.request_uri?
57
+ response = http.request(request)
58
+ unless response.is_a?(Net::HTTPSuccess)
59
+ raise "#{response.code} #{response.message}\n#{response.body}"
60
+ end
61
+ true
62
+ end
63
+
64
+ # :nodoc:
65
+ def to_s
66
+ s = super
67
+ s << ", access_token=#{short_token}"
68
+ end
69
+
70
+
71
+ protected
72
+ # :nodoc:
73
+ def initialize
74
+ super
75
+ @access_token = ""
76
+ end
77
+
78
+ # :nodoc:
79
+ def merge_params(options)
80
+ {:access_token => access_token}.merge!(options)
81
+ end
82
+
83
+ # :nodoc:
84
+ def short_token
85
+ return "" if access_token.nil? || access_token.empty?
86
+ access_token[0..3] + "..." +
87
+ access_token[(access_token.length - 4)..(access_token.length - 1)]
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,107 @@
1
+ require 'net/http'
2
+ #
3
+ # RubyMeetup is a light-weight client for the Meetup.com API version 2.
4
+ #
5
+ # ---
6
+ # Copyright (c) 2013 Long On, released under the MIT license
7
+
8
+ module RubyMeetup
9
+
10
+ # This class is abstract. It has accessor methods for configuring
11
+ # the API site. By default it is set to https://api.meetup.com but may be changed
12
+ # using the class setter method +site=+.
13
+ #
14
+ # The gem supports API request with two authentication strategies:
15
+ # <b>API Key</b> and <b>OAuth 2</b> via the concrete classes *ApiKeyClient* and
16
+ # *AuthenticatedClient*, respectively. More information can be found in the
17
+ # specific class documentation.
18
+ #
19
+ # Example usage:
20
+ #
21
+ # > require 'ruby_meetup'
22
+ # > RubyMeetup::ApiKeyClient.key = 'abcd000000000000000wxyz'
23
+ # > client = RubyMeetup::ApiKeyClient.new
24
+ # > json_string = client.get_path("/2/groups", {:group_id => 390230})
25
+ # > second_result = client.get({:group_id => 939203})
26
+ #
27
+ # If successful the captured response is a raw JSON string. The response can then
28
+ # be processed using a JSON parser. Otherwise an exception is raised.
29
+ #
30
+ # Typically, ApiKeyClient class is used to read data while the AuthenticatedClient
31
+ # class is used for both read and write data, subject to Meetup API permission scopes.
32
+ #
33
+ # ---
34
+ # Copyright (c) 2013 Long On, released under the MIT license
35
+
36
+ class Client
37
+ @@site = "https://api.meetup.com"
38
+
39
+ attr_accessor :path
40
+
41
+ # == class methods
42
+
43
+ # Retun the configured API endpoint
44
+ def self.site
45
+ @@site
46
+ end
47
+ # Set the global API endpoint
48
+ def self.site=string
49
+ @@site = string
50
+ end
51
+
52
+ # == instance methods
53
+
54
+ # A convenience method to set @path and @options in the same API call.
55
+ # Return a JSON string if successful, otherwise an Exception
56
+ def get_path(path, options={})
57
+ self.path = path
58
+ get(options)
59
+ end
60
+
61
+ # Make a GET API call with the current path value and @options.
62
+ # Return a JSON string if successful, otherwise an Exception
63
+ def get(options={})
64
+ uri = new_uri
65
+ params = merge_params(options)
66
+ uri.query = URI.encode_www_form(params)
67
+
68
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
69
+ request = Net::HTTP::Get.new(uri)
70
+ response = http.request(request)
71
+ unless response.is_a?(Net::HTTPSuccess)
72
+ raise "#{response.code} #{response.message}\n#{response.body}"
73
+ end
74
+ return response.body
75
+ end
76
+ end
77
+
78
+ # :nodoc:
79
+ def to_s
80
+ "#{self.class.name}: site=#{@@site}, path=#{path}"
81
+ end
82
+
83
+
84
+ protected
85
+ # :nodoc:
86
+ def initialize
87
+ @path = ""
88
+ end
89
+
90
+ # :nodoc:
91
+ def new_uri
92
+ URI(@@site + path)
93
+ end
94
+
95
+ # :nodoc:
96
+ def merge_params(options={})
97
+ options
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+ # :nodoc:
104
+ require 'authenticated_client'
105
+ # :nodoc:
106
+ require 'api_key_client'
107
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_meetup2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Long On
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-02 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A light-weight Ruby client for working with the Meetup API
14
+ email: on.long.on@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/ruby_meetup.rb
20
+ - lib/api_key_client.rb
21
+ - lib/authenticated_client.rb
22
+ homepage: https://github.com/fun-ruby/ruby-meetup2
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements:
41
+ - ruby net/http[s]
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.3
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Meetup API v2 Ruby client
47
+ test_files: []