Class: Viagogo::Client
- Inherits:
-
Object
- Object
- Viagogo::Client
- Defined in:
- lib/viagogo.rb
Constant Summary collapse
- AUTH_URL =
'http://api.viagogo.net/Public/SimpleOAuthAccessRequest'
- EVENT_ENDPOINT =
'http://api.viagogo.net/Public/Event/Search'
Instance Attribute Summary collapse
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_secret ⇒ Object
Returns the value of attribute token_secret.
Instance Method Summary collapse
-
#initialize(consumer_key, consumer_secret, token = nil, token_secret = nil) ⇒ Client
constructor
A new instance of Client.
- #search_events(text) ⇒ Object
- #valid_token? ⇒ Boolean
Constructor Details
#initialize(consumer_key, consumer_secret, token = nil, token_secret = nil) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/viagogo.rb', line 14 def initialize(consumer_key, consumer_secret, token = nil, token_secret = nil) @consumer_key = consumer_key @consumer_secret = consumer_secret @token = token @token_secret = token_secret fetch_public_token unless token_secret # fetch public token if not supplied # p @consumer_key # p @consumer_secret # p @token # p @token_secret end |
Instance Attribute Details
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
12 13 14 |
# File 'lib/viagogo.rb', line 12 def consumer_key @consumer_key end |
#consumer_secret ⇒ Object
Returns the value of attribute consumer_secret.
12 13 14 |
# File 'lib/viagogo.rb', line 12 def consumer_secret @consumer_secret end |
#token ⇒ Object
Returns the value of attribute token.
12 13 14 |
# File 'lib/viagogo.rb', line 12 def token @token end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
12 13 14 |
# File 'lib/viagogo.rb', line 12 def token_secret @token_secret end |
Instance Method Details
#search_events(text) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/viagogo.rb', line 39 def search_events(text) # @hrows OpenURI::HTTPError exception when token is not valid r = OAuth1::Helper.new('GET', EVENT_ENDPOINT, {searchText:text},{ consumer_key: @consumer_key, consumer_secret: @consumer_secret, token: @token, token_secret: @token_secret}) request_url = r.full_url open(request_url, 'Content-Type' => 'application/json') do |f| json = f.read result = JSON.parse(json) if json events = result['Results'] if result end end |
#valid_token? ⇒ Boolean
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/viagogo.rb', line 26 def valid_token? 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}) request_url = r.full_url begin open(request_url) true rescue OpenURI::HTTPError => e false end end |