viagogo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +22 -0
- data/README.md +40 -0
- data/Rakefile +7 -0
- data/lib/viagogo/oauth1_helper.rb +61 -0
- data/lib/viagogo/version.rb +3 -0
- data/lib/viagogo.rb +66 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/viagogo_spec.rb +39 -0
- data/viagogo.gemspec +26 -0
- metadata +130 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 YI FU
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 fuyi
|
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,40 @@
|
|
1
|
+
# Viagogo
|
2
|
+
|
3
|
+
This is a ruby client library for viagogo api
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'viagogo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install viagogo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Create a viagogo ruby client by providing consumer_key and consumer_secret
|
22
|
+
|
23
|
+
client = Viagogo::Client.new('you consumer key', 'your consumer_secret')
|
24
|
+
|
25
|
+
Search for events by free text
|
26
|
+
|
27
|
+
client.search_events('free text here')
|
28
|
+
|
29
|
+
## Feature
|
30
|
+
search events by free text
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
39
|
+
|
40
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
require 'cgi'
|
3
|
+
require 'base64'
|
4
|
+
require 'openssl'
|
5
|
+
require 'securerandom'
|
6
|
+
|
7
|
+
module OAuth1
|
8
|
+
class Helper
|
9
|
+
attr_reader :url_params
|
10
|
+
|
11
|
+
def initialize(method, url, params, options)
|
12
|
+
options = {
|
13
|
+
version: "1.0",
|
14
|
+
signature_method: 'HMAC-SHA1',
|
15
|
+
timestamp: Time.now.to_i.to_s,
|
16
|
+
nonce: SecureRandom.uuid
|
17
|
+
# token: ""
|
18
|
+
}.merge(options)
|
19
|
+
@consumer_secret = options.delete(:consumer_secret)
|
20
|
+
@token_secret = options.delete(:token_secret)
|
21
|
+
@url_params = params.merge(prepend_oauth_to_key(options))
|
22
|
+
|
23
|
+
@method = method.to_s.upcase
|
24
|
+
@url = Addressable::URI.parse(url)
|
25
|
+
end
|
26
|
+
|
27
|
+
def signature_base
|
28
|
+
@url_params.delete :oauth_signature
|
29
|
+
# p @url_params, @url.to_s, url_with_params.query
|
30
|
+
[@method, @url.to_s, url_with_params.query].map{|v| CGI.escape(v) }.join('&')
|
31
|
+
end
|
32
|
+
|
33
|
+
def append_signature_to_params
|
34
|
+
@url_params[:oauth_signature] = hmac_sha1_signature(key, signature_base)
|
35
|
+
end
|
36
|
+
|
37
|
+
def full_url
|
38
|
+
append_signature_to_params
|
39
|
+
url_with_params.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def key
|
44
|
+
@token_secret ? "#{CGI.escape(@consumer_secret)}&#{CGI.escape(@token_secret)}" : "#{CGI.escape(@consumer_secret)}&"
|
45
|
+
end
|
46
|
+
|
47
|
+
def url_with_params
|
48
|
+
@url.dup.tap{|url| url.query_values = url_params }
|
49
|
+
end
|
50
|
+
|
51
|
+
def prepend_oauth_to_key(options)
|
52
|
+
Hash[options.map{|key, value| ["oauth_#{key}".to_sym, value]}]
|
53
|
+
end
|
54
|
+
|
55
|
+
def hmac_sha1_signature(key, signature_string)
|
56
|
+
digest = OpenSSL::Digest::Digest.new('sha1')
|
57
|
+
hmac = OpenSSL::HMAC.digest(digest, key, signature_string)
|
58
|
+
Base64.encode64(hmac).chomp.gsub(/\n/, '')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/viagogo.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require "viagogo/version"
|
2
|
+
require 'viagogo/oauth1_helper'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Viagogo
|
7
|
+
class Client
|
8
|
+
|
9
|
+
AUTH_URL = 'http://api.viagogo.net/Public/SimpleOAuthAccessRequest'
|
10
|
+
EVENT_ENDPOINT = 'http://api.viagogo.net/Public/Event/Search'
|
11
|
+
|
12
|
+
attr_accessor :consumer_key, :consumer_secret, :token, :token_secret
|
13
|
+
|
14
|
+
def initialize(consumer_key, consumer_secret, token = nil, token_secret = nil)
|
15
|
+
@consumer_key = consumer_key
|
16
|
+
@consumer_secret = consumer_secret
|
17
|
+
@token = token
|
18
|
+
@token_secret = token_secret
|
19
|
+
fetch_public_token unless token_secret # fetch public token if not supplied
|
20
|
+
# p @consumer_key
|
21
|
+
# p @consumer_secret
|
22
|
+
# p @token
|
23
|
+
# p @token_secret
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_token?
|
27
|
+
r = OAuth1::Helper.new('GET', 'http://api.viagogo.net/Public/Category/1', {},{ consumer_key: @consumer_key, consumer_secret: @consumer_secret, token: @token, token_secret: @token_secret})
|
28
|
+
request_url = r.full_url
|
29
|
+
begin
|
30
|
+
open(request_url)
|
31
|
+
true
|
32
|
+
rescue OpenURI::HTTPError => e
|
33
|
+
false
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def search_events(text)
|
40
|
+
# @hrows OpenURI::HTTPError exception when token is not valid
|
41
|
+
r = OAuth1::Helper.new('GET', EVENT_ENDPOINT, {searchText:text},{ consumer_key: @consumer_key, consumer_secret: @consumer_secret, token: @token, token_secret: @token_secret})
|
42
|
+
request_url = r.full_url
|
43
|
+
open(request_url, 'Content-Type' => 'application/json') do |f|
|
44
|
+
json = f.read
|
45
|
+
result = JSON.parse(json) if json
|
46
|
+
events = result['Results'] if result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch_public_token
|
51
|
+
o1 = OAuth1::Helper.new('GET',AUTH_URL, {scope: 'API.Public'},{ consumer_key: @consumer_key, consumer_secret: @consumer_secret})
|
52
|
+
auth_url = o1.full_url
|
53
|
+
open(auth_url) do |f|
|
54
|
+
str = f.read
|
55
|
+
arr = str.split('&')
|
56
|
+
token = arr[0][12..-1]
|
57
|
+
token_secret = arr[1][19..-1]
|
58
|
+
@token = CGI.unescape(token)
|
59
|
+
@token_secret = CGI.unescape(token_secret)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private :fetch_public_token
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'viagogo'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viagogo::Client do
|
4
|
+
let(:consumer_key) {"some consumer key"}
|
5
|
+
let(:consumer_secret) {"some consumer secret"}
|
6
|
+
it '#initialize can fetch token and token secret when creation, if not supplied' do
|
7
|
+
# c = Viagogo::Client.new(consumer_key, consumer_secret)
|
8
|
+
c = Viagogo::Client.new('Xfu2mHZ9wkvy3gs', 'iSsBKQzW2h4TyHkvl5jZJp0ONe3LAq')
|
9
|
+
c.token.length.should > 10
|
10
|
+
c.token_secret.length.should > 10
|
11
|
+
end
|
12
|
+
|
13
|
+
it '#valid_token? can verify if token and token secret are valid' do
|
14
|
+
c = Viagogo::Client.new(consumer_key, consumer_secret,'aaaaaaa','bbbbbbbb')
|
15
|
+
result = c.valid_token?
|
16
|
+
result.should be false
|
17
|
+
|
18
|
+
c2 = Viagogo::Client.new('Xfu2mHZ9wkvy3gs', 'iSsBKQzW2h4TyHkvl5jZJp0ONe3LAq')
|
19
|
+
result = c2.valid_token?
|
20
|
+
result.should be true
|
21
|
+
|
22
|
+
token = c2.token
|
23
|
+
token_secret = c2.token_secret
|
24
|
+
c3 = Viagogo::Client.new('Xfu2mHZ9wkvy3gs', 'iSsBKQzW2h4TyHkvl5jZJp0ONe3LAq',token, token_secret)
|
25
|
+
result = c3.valid_token?
|
26
|
+
result.should be true
|
27
|
+
end
|
28
|
+
|
29
|
+
it '#search_events can search for events by free text' do
|
30
|
+
c = Viagogo::Client.new('Xfu2mHZ9wkvy3gs', 'iSsBKQzW2h4TyHkvl5jZJp0ONe3LAq')
|
31
|
+
events = c.search_events 'Manchester United'
|
32
|
+
events.should be(Array)
|
33
|
+
end
|
34
|
+
|
35
|
+
it '#search_events should throw error' do
|
36
|
+
c = Viagogo::Client.new(consumer_key, consumer_secret,'aaaaaaa','bbbbbbbb')
|
37
|
+
expect{c.search_events('Manchester United')}.to raise_error(OpenURI::HTTPError)
|
38
|
+
end
|
39
|
+
end
|
data/viagogo.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'viagogo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "viagogo"
|
8
|
+
spec.version = Viagogo::VERSION
|
9
|
+
spec.authors = ["fuyi"]
|
10
|
+
spec.email = ["yvesfu@gmail.com"]
|
11
|
+
spec.description = %q{viagogo api ruby client}
|
12
|
+
spec.summary = %q{viagogo api ruby client}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "addressable"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viagogo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- fuyi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: addressable
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: viagogo api ruby client
|
79
|
+
email:
|
80
|
+
- yvesfu@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- lib/viagogo.rb
|
92
|
+
- lib/viagogo/oauth1_helper.rb
|
93
|
+
- lib/viagogo/version.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
- spec/viagogo_spec.rb
|
96
|
+
- viagogo.gemspec
|
97
|
+
homepage: ''
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: -1767033637420559844
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
hash: -1767033637420559844
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 1.8.25
|
125
|
+
signing_key:
|
126
|
+
specification_version: 3
|
127
|
+
summary: viagogo api ruby client
|
128
|
+
test_files:
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/viagogo_spec.rb
|