meetup_client 0.0.5

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.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # The Meetup Ruby Gem
2
+
3
+ A Ruby interface to the Meetup.com API.
4
+
5
+ ## Installation
6
+ gem install meetup_client
7
+
8
+ ## Quick Start Guide
9
+ This gem is a simple and easy-to-use interface to the Meetup.com API.
10
+ The methods you can call with the gem are:
11
+
12
+ -categories
13
+
14
+ -checkins
15
+
16
+ -cities
17
+
18
+ -events
19
+
20
+ -members
21
+
22
+ -messaging
23
+
24
+ -photos
25
+
26
+ -profiles
27
+
28
+ -rsvps
29
+
30
+ -streams
31
+
32
+ The parameters for each request have to be passed with a hash (i.e. { category: '1', city: 'London', country: 'GB', status: 'upcoming'} )
33
+
34
+ First, [get a Meetup API key][register].
35
+
36
+ Then, create a new file config/initializers/meetup_client.rb, and put the following content in it:
37
+
38
+ ```ruby
39
+ MeetupClient.configure do |config|
40
+ config.api_key = MEETUP_API_KEY
41
+ end
42
+ ```
43
+
44
+ [Have a look at the Meetup API website for details about the API] [check_api]
45
+
46
+ [register]: http://www.meetup.com/meetup_api/key/
47
+ [check_api]: http://www.meetup.com/meetup_api/
48
+
49
+ ## Usage Examples
50
+
51
+ **To get events in London about Arts & Culture**
52
+
53
+ ```ruby
54
+ params = { category: '1',
55
+ city: 'London',
56
+ country: 'GB',
57
+ status: 'upcoming',
58
+ format: 'json',
59
+ page: '50'}
60
+ meetup_api = MeetupApi.new
61
+ @events = meetup_api.open_events(params)
62
+ ```
63
+ Any response will be exactly what the Meetup API returns. In the case above, it will be a json containing
64
+ a list of events.
65
+
66
+ ## Supported Ruby Versions
67
+ This library aims to support and is [tested against][travis] the following Ruby
68
+ implementations:
69
+
70
+ * Ruby 1.9.2
71
+ * Ruby 1.9.3
72
+ * Ruby 2.0.0
73
+
74
+ If something doesn't work on one of these interpreters, it's a bug.
75
+
76
+ This library may inadvertently work (or seem to work) on other Ruby
77
+ implementations, however support will only be provided for the versions listed
78
+ above.
79
+
80
+ If you would like this library to support another Ruby version, you may
81
+ volunteer to be a maintainer. Being a maintainer entails making sure all tests
82
+ run and pass on that implementation. When something breaks on your
83
+ implementation, you will be responsible for providing patches in a timely
84
+ fashion. If critical issues for a particular implementation exist at the time
85
+ of a major release, support for that Ruby version may be dropped.
86
+
87
+
88
+ ## Copyright
89
+ Copyright (c) 2013 Cosimo Ranieri.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ MeetupApiGem::Application.load_tasks
@@ -0,0 +1,30 @@
1
+ module ApiCallers
2
+ class HttpRequest
3
+ CHARSET = 'UTF-8'
4
+
5
+ def initialize(uri, method = 'get')
6
+ @in_uri = uri
7
+ @method = method
8
+ end
9
+
10
+ def make_request
11
+ uri = URI.parse(@in_uri)
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ response = http.request(class_to_call.new(uri.request_uri, headers))
14
+ format_response(response.body)
15
+ end
16
+
17
+ def format_response(response_body); response_body; end;
18
+
19
+ private
20
+
21
+ def headers
22
+ { 'Accept-Charset' => CHARSET }
23
+ end
24
+
25
+ def class_to_call
26
+ "Net::HTTP::#{@method.capitalize}".constantize
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ require 'net/http'
2
+
3
+ module ApiCallers
4
+ class HttpRequester
5
+ def initialize(requester)
6
+ @requester = requester
7
+ end
8
+
9
+ def execute_request
10
+ @requester.make_request
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'api_callers/http_request'
2
+
3
+ module ApiCallers
4
+ class JsonRequest < HttpRequest
5
+ def format_response(response_body)
6
+ ActiveSupport::JSON.decode(clean_response_body(response_body))
7
+ end
8
+
9
+ private
10
+
11
+ def clean_response_body(response_body)
12
+ ActionController::Base.helpers.strip_tags(response_body.gsub('\"','').force_encoding(CHARSET))
13
+ end
14
+ end
15
+ end
data/lib/meetup_api.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'api_callers/json_request'
2
+ require 'api_callers/http_requester'
3
+
4
+ class MeetupApi
5
+ BASE_URL = 'http://api.meetup.com/2/'
6
+
7
+ def method_request(method, params)
8
+ json_request = ApiCallers::JsonRequest.new("#{BASE_URL}#{method}?#{query_string(params.merge( { key: MeetupClient.config.api_key } ))}")
9
+ requester = ApiCallers::HttpRequester.new(json_request)
10
+ requester.execute_request
11
+ end
12
+
13
+ def method_missing(method, *args, &block)
14
+ self.method_request(method, args[0])
15
+ end
16
+
17
+ private
18
+
19
+ def query_string(params)
20
+ params.map { |k,v| "#{k}=#{v}" }.join("&")
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'meetup_client/configuration'
2
+ require 'meetup_api'
3
+
4
+ module MeetupClient
5
+ class << self
6
+ def configure(&block)
7
+ yield @config ||= ::MeetupClient::Configuration.new
8
+ end
9
+
10
+ def config
11
+ @config
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ module MeetupClient
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ module MeetupClient
2
+ class Version
3
+ def to_s
4
+ '0.0.1'
5
+ end
6
+ end
7
+ end
8
+
9
+
@@ -0,0 +1,18 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'meetup_client'
7
+ s.date = '2013-07-25'
8
+ s.summary = "Easy way to access the Meetup.com API"
9
+ s.description = "Easy way to access the Meetup.com API"
10
+ s.authors = ["Cosimo Ranieri"]
11
+ s.email = 'co.ranieri@gmail.com'
12
+ s.files = %w(README.md Rakefile meetup_client.gemspec)
13
+ s.files += Dir.glob("lib/**/*.rb")
14
+ s.files += Dir.glob("spec/**/*")
15
+ s.version = '0.0.5'
16
+ s.homepage = 'https://rubygems.org/gems/meetup_client'
17
+ s.license = 'MIT'
18
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe ::ApiCallers::HttpRequest do
5
+ subject { ::ApiCallers::HttpRequest.new('') }
6
+
7
+ describe "#headers" do
8
+ it "returns { 'Accept-Charset' => 'utf-8' }" do
9
+ expect(subject.send(:headers)).to eq({ 'Accept-Charset' => 'UTF-8' })
10
+ end
11
+ end
12
+
13
+ describe "#class_to_call" do
14
+ it "returns Net::HTTP::Get by default" do
15
+ expect(subject.send(:class_to_call)).to eq Net::HTTP::Get
16
+ end
17
+
18
+ it "returns the class to call based on the request method, whether it is 'get', 'post', or 'delete'" do
19
+ json_request = ::ApiCallers::JsonRequest.new('', 'post')
20
+ expect(json_request.send(:class_to_call)).to eq Net::HTTP::Post
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+ require 'net/http'
3
+
4
+ describe ::ApiCallers::JsonRequest do
5
+ subject { ::ApiCallers::JsonRequest.new('') }
6
+
7
+ describe "#clean_response_body" do
8
+ let(:body_response) { 'I\'m the \"Best\"' }
9
+
10
+ it "removed \" from the passed text " do
11
+ expect(subject.send(:clean_response_body, body_response)).to eq 'I\'m the Best'
12
+ end
13
+
14
+ it "forces the encoding to utf-8" do
15
+ body_response.encode!('windows-1251')
16
+ expect(subject.send(:clean_response_body, body_response).encoding.to_s).to eq 'UTF-8'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe MeetupApi do
5
+ describe "#query_string" do
6
+ subject { MeetupApi.new }
7
+ it "returns a valid query string" do
8
+ params = { category: '1',
9
+ status: 'upcoming',
10
+ time: '0,1m' }
11
+ expect(subject.send(:query_string, params)).to eq 'category=1&status=upcoming&time=0,1m'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,38 @@
1
+ # This file is copied to spec/ when you run 'rails generate rspec:install'
2
+ ENV["RAILS_ENV"] ||= 'test'
3
+ require File.expand_path("../../config/environment", __FILE__)
4
+ require 'rspec/rails'
5
+ require 'rspec/autorun'
6
+
7
+ # Requires supporting ruby files with custom matchers and macros, etc,
8
+ # in spec/support/ and its subdirectories.
9
+ Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
10
+
11
+ RSpec.configure do |config|
12
+ # ## Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+
20
+ # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
24
+ # examples within a transaction, remove the following line or assign false
25
+ # instead of true.
26
+ config.use_transactional_fixtures = true
27
+
28
+ # If true, the base class of anonymous controllers will be inferred
29
+ # automatically. This will be the default behavior in future versions of
30
+ # rspec-rails.
31
+ config.infer_base_class_for_anonymous_controllers = false
32
+
33
+ # Run specs in random order to surface order dependencies. If you find an
34
+ # order dependency and want to debug it, you can fix the order by providing
35
+ # the seed, which is printed after each run.
36
+ # --seed 1234
37
+ config.order = "random"
38
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: meetup_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Cosimo Ranieri
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Easy way to access the Meetup.com API
15
+ email: co.ranieri@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - Rakefile
22
+ - meetup_client.gemspec
23
+ - lib/api_callers/http_request.rb
24
+ - lib/api_callers/http_requester.rb
25
+ - lib/api_callers/json_request.rb
26
+ - lib/meetup_api.rb
27
+ - lib/meetup_client/configuration.rb
28
+ - lib/meetup_client/version.rb
29
+ - lib/meetup_client.rb
30
+ - spec/api_callers/http_request_spec.rb
31
+ - spec/api_callers/json_request_spec.rb
32
+ - spec/meetup_api_spec.rb
33
+ - spec/spec_helper.rb
34
+ homepage: https://rubygems.org/gems/meetup_client
35
+ licenses:
36
+ - MIT
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.23
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: Easy way to access the Meetup.com API
59
+ test_files: []