eventful_api 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ pkg
3
+ rdoc
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eventful_api.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Tekin Suleyman.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Tekin Suleyman
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # EventfulApi
2
+
3
+ [![Build Status](https://api.travis-ci.org/tekin/eventful_api.png)](http://travis-ci.org/tekin/eventful_api)
4
+
5
+ ## Description
6
+
7
+ A Ruby library for accessing the eventful.com API. It supports
8
+ their new OAuth authentication method.
9
+
10
+ ## Installation
11
+
12
+ gem install eventful_api
13
+
14
+ ## Configuration and usage
15
+
16
+ The Eventful API requires authentication via [OAuth 1.0](http://tools.ietf.org/html/rfc5849) to access resources on
17
+ behalf of Eventful users. You can register your application at
18
+ [http://api.eventful.com/keys](http://api.eventful.com/keys). Once registered, you'll need to generate your
19
+ OAuth consumer and secret.
20
+
21
+ Configure `EventfulApi` with your application key, OAuth consumer key and your
22
+ OAuth consumer secret:
23
+
24
+ ```ruby
25
+ EventfulApi.configure do |config|
26
+ config.application_key = YOUR_APPLICATION_KEY
27
+ config.consumer_key = YOUR_CONSUMER_KEY
28
+ config.consumer_secret = YOUR_CONSUMER_SECRET
29
+ end
30
+ ```
31
+
32
+ You can make requests on behalf of a user once you have acquired their OAuth
33
+ access token/secret pair by instantiating an `EventfulApi::Client`:
34
+
35
+ ```ruby
36
+ client = EventfulApi::Client.new(:oauth_token => 'token', :oauth_token_secret => 'token secret')
37
+
38
+ responsh_hash = client.post('/events/new', event_param_hash)
39
+ response_hash = client.get('/events/get', {:id => 'E0-001-053639493-9'})
40
+ ```
41
+
42
+ EventfulApi makes requests to Eventful's JSON interface, returning the Hash equivalent of the JSON responses.
43
+
44
+ ## OAuth authentication
45
+
46
+ You are free to acquire OAuth authorization from your users using your own process. However, EventfulApi does provide a
47
+ convenient facade for generating both request tokens and access tokens.
48
+
49
+ ### Step 1. Requesting a token and redirect the user
50
+
51
+ ```ruby
52
+ request_token = EventfulApi.get_request_token(:oauth_callback => 'http://example.com/callback')
53
+ # store the request token and secret for later use and redirect the user
54
+ session[:request_token] = request_token.token
55
+ session[:request_secret] = request_token.secret
56
+ redirect_to token.redirect_url
57
+ ```
58
+
59
+ ### Step 2. Acquiring an access token during the callback
60
+
61
+ ```ruby
62
+ # Reconstruct the request token using the token and secret saved in the session
63
+ request_token = OAuth::RequstToken.new(EventfulApi.oauth_consumer, session[:request_token], session[:request_secret])
64
+ # Get an access token from Eventful using the oauth_verifier param
65
+ access_token = request_token.get_access_token(:oauth_verifier => params[:oauth_verifier])
66
+ # You now have a verified token and secret ready to create a client
67
+ client = EventfulApi::Client.new(:oauth_token => access_token.token, :oauth_secret => access_token.secret)
68
+ ```
69
+
70
+ License
71
+ -------
72
+ Released under the MIT License. See the [LICENSE][license] file for further details.
73
+
74
+ [license]: LICENSE.md
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList["test/**/test_*.rb"]
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => ["test"]
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eventful_api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "eventful_api"
8
+ gem.version = EventfulApi::VERSION
9
+ gem.authors = ["Tekin Suleyman"]
10
+ gem.email = ["tekin@tekin.co.uk"]
11
+ gem.description = %q{Ruby library for accessing the eventful.com API}
12
+ gem.summary = gem.description
13
+ gem.homepage = "http://github.com/tekin/eventful_api"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "oauth", ["~> 0.3.6"]
21
+ gem.add_dependency "multi_json", ["~> 1.5.0"]
22
+ gem.add_dependency "addressable", ["~> 2.3.4"]
23
+
24
+ gem.add_development_dependency "rake", ["~> 10.0.4"]
25
+ gem.add_development_dependency "test-unit", ["~> 2.5.4"]
26
+ gem.add_development_dependency "mocha", ["~> 0.13.2"]
27
+ end
@@ -0,0 +1,39 @@
1
+ require 'addressable/uri'
2
+ require 'multi_json'
3
+
4
+ module EventfulApi
5
+ class Client
6
+ API_URL = 'http://api.eventful.com'
7
+ attr_reader :access_token, :oauth_consumer
8
+
9
+ def initialize(params)
10
+ @oauth_consumer = OAuth::Consumer.new(EventfulApi.consumer_key, EventfulApi.consumer_secret, :site => API_URL, :scheme => EventfulApi::SCHEME)
11
+ @access_token = OAuth::AccessToken.new(oauth_consumer, params[:oauth_token], params[:oauth_secret])
12
+ end
13
+
14
+ def get(method, params)
15
+ response = access_token.get get_path(method, params)
16
+ MultiJson.load response.body
17
+ end
18
+
19
+ def post(method, params)
20
+ response = access_token.post(json_path(method), api_params(params))
21
+ MultiJson.load response.body
22
+ end
23
+
24
+ private
25
+
26
+ def get_path(path, params)
27
+ Addressable::URI.new(:path => json_path(path), :query_values => api_params(params)).to_s
28
+ end
29
+
30
+ def json_path(path)
31
+ "/json#{path}"
32
+ end
33
+
34
+ def api_params(params)
35
+ params.merge(:app_key => EventfulApi.app_key)
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,3 @@
1
+ module EventfulApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'forwardable'
2
+ require 'oauth'
3
+ require 'eventful_api/client'
4
+ require 'eventful_api/version'
5
+
6
+ module EventfulApi
7
+ SITE_URL = 'http://eventful.com'
8
+ SCHEME = :query_string
9
+
10
+ @config = Struct.new(:consumer_key, :consumer_secret, :app_key).new
11
+
12
+ class << self
13
+ extend Forwardable
14
+
15
+ def_delegators :@config, :consumer_key, :consumer_secret, :app_key
16
+
17
+ def configure(&block)
18
+ yield @config
19
+ end
20
+
21
+ def oauth_consumer
22
+ @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => SITE_URL, :scheme => SCHEME)
23
+ end
24
+
25
+ def get_request_token(options)
26
+ oauth_consumer.get_request_token(options)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,67 @@
1
+ require 'test_helper'
2
+
3
+ class TestEventfulApi < MiniTest::Unit::TestCase
4
+ def setup
5
+ EventfulApi.configure do |config|
6
+ config.consumer_key = 'key'
7
+ config.consumer_secret = 'secret'
8
+ config.app_key = 'app_key'
9
+ end
10
+ end
11
+
12
+ describe EventfulApi::Client do
13
+ before do
14
+ @client = EventfulApi::Client.new(:oauth_token => 'client_key', :oauth_secret => 'client_secret')
15
+ end
16
+
17
+ it 'has a oauth consumer for accessing the Eventful API' do
18
+ consumer = @client.oauth_consumer
19
+
20
+ assert consumer.is_a?(OAuth::Consumer)
21
+ assert_equal EventfulApi::Client::API_URL, consumer.site
22
+ assert_equal EventfulApi.consumer_key, consumer.key
23
+ assert_equal EventfulApi.consumer_secret, consumer.secret
24
+ end
25
+
26
+ it 'has an ouath access token' do
27
+ access_token = @client.access_token
28
+
29
+ assert access_token.is_a?(OAuth::AccessToken)
30
+ assert_equal 'client_key', access_token.token
31
+ assert_equal 'client_secret', access_token.secret
32
+ assert_equal @client.oauth_consumer, access_token.consumer
33
+ end
34
+
35
+ describe 'making a GET API call with parameters' do
36
+ it 'transforms the request and delegates the call through the access token' do
37
+ @client.access_token.expects(:get).with("/json/events/get?app_key=#{EventfulApi.app_key}&id=E0-001-053639493-9").returns(mock_response)
38
+ @client.get('/events/get', :id => 'E0-001-053639493-9')
39
+ end
40
+
41
+ it 'returns a hash representation of the response body' do
42
+ @client.access_token.expects(:get).with("/json/events/get?app_key=#{EventfulApi.app_key}&id=E0-001-054172192-4").returns(mock_response)
43
+ response = @client.get('/events/get', :id => 'E0-001-054172192-4')
44
+
45
+ assert_equal ({'foo' => 'bar'}), response
46
+ end
47
+ end
48
+
49
+ describe 'making a POST API call with parameters' do
50
+ it 'transforms the request and delegates the call through the access token' do
51
+ @client.access_token.expects(:post).with('/json/events/new', {:id => 'E0-001-053639493-9', :app_key => EventfulApi.app_key}).returns(mock_response)
52
+ response = @client.post('/events/new', :id => 'E0-001-053639493-9')
53
+ end
54
+
55
+ it 'returns a hash representation of the response body' do
56
+ @client.access_token.expects(:post).with('/json/events/new', {:id => 'E0-001-054172192-4', :app_key => EventfulApi.app_key}).returns(mock_response)
57
+ response = @client.post('/events/new', :id => 'E0-001-054172192-4')
58
+
59
+ assert_equal ({'foo' => 'bar'}), response
60
+ end
61
+ end
62
+
63
+ def mock_response
64
+ Struct.new(:body).new('{"foo": "bar"}')
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class TestEventfulApi < MiniTest::Unit::TestCase
4
+
5
+ describe EventfulApi do
6
+ before do
7
+ EventfulApi.configure do |config|
8
+ config.consumer_key = 'key'
9
+ config.consumer_secret = 'secret'
10
+ config.app_key = 'app_key'
11
+ end
12
+ end
13
+
14
+ it 'has a consumer key' do
15
+ assert_equal 'key', EventfulApi.consumer_key
16
+ end
17
+
18
+ it 'has a consumer secret' do
19
+ assert_equal 'secret', EventfulApi.consumer_secret
20
+ end
21
+
22
+ it 'has an app key' do
23
+ assert_equal 'app_key', EventfulApi.app_key
24
+ end
25
+
26
+ it 'has an oauth consumer' do
27
+ consumer = EventfulApi.oauth_consumer
28
+
29
+ assert consumer.is_a?(OAuth::Consumer)
30
+ assert_equal EventfulApi.consumer_key, consumer.key
31
+ assert_equal EventfulApi.consumer_secret, consumer.secret
32
+ assert_equal EventfulApi::SITE_URL, consumer.site
33
+ assert_equal EventfulApi::SCHEME, consumer.scheme
34
+ end
35
+
36
+ it 'delegates request token generation to its oauth consumer' do
37
+ options = { :callback_url => 'http://example.com/callback'}
38
+ EventfulApi.oauth_consumer.expects(:get_request_token).with(options).returns('token')
39
+
40
+ assert_equal 'token', EventfulApi.get_request_token(options)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'mocha/setup'
4
+
5
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
6
+ require 'eventful_api'
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eventful_api
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Tekin Suleyman
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: oauth
16
+ type: :runtime
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.6
22
+ none: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.3.6
28
+ none: false
29
+ prerelease: false
30
+ - !ruby/object:Gem::Dependency
31
+ name: multi_json
32
+ type: :runtime
33
+ requirement: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.5.0
38
+ none: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.5.0
44
+ none: false
45
+ prerelease: false
46
+ - !ruby/object:Gem::Dependency
47
+ name: addressable
48
+ type: :runtime
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.3.4
54
+ none: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 2.3.4
60
+ none: false
61
+ prerelease: false
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ type: :development
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 10.0.4
70
+ none: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 10.0.4
76
+ none: false
77
+ prerelease: false
78
+ - !ruby/object:Gem::Dependency
79
+ name: test-unit
80
+ type: :development
81
+ requirement: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.5.4
86
+ none: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: 2.5.4
92
+ none: false
93
+ prerelease: false
94
+ - !ruby/object:Gem::Dependency
95
+ name: mocha
96
+ type: :development
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.13.2
102
+ none: false
103
+ version_requirements: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: 0.13.2
108
+ none: false
109
+ prerelease: false
110
+ description: Ruby library for accessing the eventful.com API
111
+ email:
112
+ - tekin@tekin.co.uk
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE.md
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - eventful_api.gemspec
124
+ - lib/eventful_api.rb
125
+ - lib/eventful_api/client.rb
126
+ - lib/eventful_api/version.rb
127
+ - test/test_client.rb
128
+ - test/test_eventful_api.rb
129
+ - test/test_helper.rb
130
+ homepage: http://github.com/tekin/eventful_api
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ segments:
141
+ - 0
142
+ hash: 2481929510141400674
143
+ version: '0'
144
+ none: false
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ segments:
150
+ - 0
151
+ hash: 2481929510141400674
152
+ version: '0'
153
+ none: false
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.25
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Ruby library for accessing the eventful.com API
160
+ test_files:
161
+ - test/test_client.rb
162
+ - test/test_eventful_api.rb
163
+ - test/test_helper.rb