stubhub 0.0.1 → 0.0.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stubhub
2
2
 
3
- TODO: Write a gem description
3
+ A gem for accessing the StubHub API
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,37 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Examples
22
+
23
+ ```ruby
24
+
25
+ # find a ticket by ticket id
26
+ Stubhub::Ticket.find_by_ticket_id(487197960) # => returns a Ticket object
27
+
28
+ # find an event by event id
29
+ Stubhub::Event.find_by_event_id(4236091) # => returns an Event object
30
+
31
+ # find tickets for an specific event
32
+ # first find the event
33
+ event = Stubhub::Event.find_by_event_id(4236091) # => returns an Event object
34
+ # then call tickets method on that event
35
+ event.tickets # => returns an array of ticket objects
36
+ #return the first 20 ticket listings
37
+ event.tickets("row" => 20) # => returns an array of ticket objects
38
+ #return the second 20 ticket listings
39
+ event.tickets("start" => 20, "row" => 20) # => returns an array of ticket objects
40
+
41
+
42
+ # search for an event
43
+ Stubhub::Event.search("swedish house mafia") # => returns an Event object
44
+
45
+ # search for a venue
46
+ Stubhub::Venue.search("Oracle Arena") # => returns a Venue object
47
+
48
+ # search for a genre
49
+ Stubhub::Genre.search("ice show") # => returns a Genre object
50
+
51
+ ```
22
52
 
23
53
  ## Contributing
24
54
 
@@ -1,6 +1,7 @@
1
1
  require 'json'
2
2
  require 'httparty'
3
3
  require 'ostruct'
4
+ require 'uri'
4
5
 
5
6
  require_relative 'stubhub/document'
6
7
  require_relative 'stubhub/client'
@@ -14,11 +15,4 @@ require_relative 'stubhub/version'
14
15
 
15
16
 
16
17
  module Stubhub
17
-
18
- # EXAMPLES -----------
19
- # doc types: event, venue, genre, geo (Geography), venue_zone_section (Venue Zone Section)
20
- # puts Stubhub::Ticket.find_by_ticket_id(487197960)
21
- # puts Stubhub::Event.find_by_event_id(4236091) => individual event
22
- # puts Stubhub::Event.search("swedish house mafia")
23
- # --------------------------
24
- end
18
+ end
@@ -5,20 +5,31 @@ module Stubhub
5
5
  base_uri "http://www.stubhub.com/listingCatalog/select/?q="
6
6
  format :json
7
7
 
8
- def self.convert_query_to_url(options)
9
- options.map do |k,v|
8
+ def self.convert_query_to_url(params, options)
9
+ params.map do |k,v|
10
10
  "%2B+#{k}%3A#{v}%0D%0A"
11
- end.join << '&start=0&rows=10&wt=json'
11
+ end.join << self.defaults.merge(options).map do |k,v|
12
+ "&#{k}=#{v}"
13
+ end.join
12
14
  end
13
15
 
14
- def self.make_request(klass, options)
15
- query_url = convert_query_to_url(options)
16
+ def self.make_request(klass, params, options)
17
+ query_url = convert_query_to_url(params, options)
16
18
  result = get(query_url)
17
19
  parsed_result = JSON.parse(result.body)
18
- parsed_result["response"]["docs"].map do |doc|
20
+ objects = parsed_result["response"]["docs"].map do |doc|
19
21
  klass.new(doc)
20
22
  end
23
+ objects.length == 1 ? objects.first : objects
21
24
  end
22
25
 
26
+ def self.defaults
27
+ @options ||= {
28
+ "start" => 0,
29
+ "rows" => 10,
30
+ "wt" => "json"
31
+ }
32
+ end
33
+
23
34
  end
24
35
  end
@@ -1,17 +1,23 @@
1
1
  module Stubhub
2
2
  class Event < Document
3
3
 
4
- def self.find_by_event_id(event_id)
5
- options = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
4
+ def self.find_by_event_id(event_id, options = {})
5
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
6
6
  "event_id" => "#{event_id}"}
7
- Client.make_request(Event, options)
7
+ Client.make_request(Event, params, options)
8
8
  end
9
9
 
10
- def self.search(search_query)
11
- search_query.gsub!(/\s+/, '+')
12
- options = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
10
+ def self.search(search_query, options = {})
11
+ search_query = URI.escape(search_query)
12
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
13
13
  "description" => "#{search_query}"}
14
- Client.make_request(Event, options)
14
+ Client.make_request(Event, params, options)
15
+ end
16
+
17
+ def tickets(options = {})
18
+ params = {"stubhubDocumentType" => "ticket",
19
+ "event_id" => "#{self.event_id}"}
20
+ Client.make_request(Ticket, params, options)
15
21
  end
16
22
 
17
23
  end
@@ -1,3 +1,11 @@
1
1
  module Stubhub
2
- class Genre < Document;end
2
+ class Genre < Document
3
+ def self.search(search_query, options = {})
4
+ search_query = URI.escape(search_query)
5
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
6
+ "description" => "#{search_query}"}
7
+ Client.make_request(Event, params, options = {})
8
+ end
9
+
10
+ end
3
11
  end
@@ -1,10 +1,10 @@
1
1
  module Stubhub
2
2
  class Ticket < Document
3
3
 
4
- def self.find_by_ticket_id(ticket_id)
5
- options = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
4
+ def self.find_by_ticket_id(ticket_id, options = {})
5
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
6
6
  "id" => "#{ticket_id}"}
7
- Client.make_request(Ticket, options)
7
+ Client.make_request(Ticket, params, options = {})
8
8
  end
9
9
 
10
10
 
@@ -1,3 +1,17 @@
1
1
  module Stubhub
2
- class Venue < Document;end
2
+ class Venue < Document
3
+ def self.find_by_venue_id(venue_id, options = {})
4
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
5
+ "venue_id" => "#{venue_id}"}
6
+ Client.make_request(Venue, params, options = {})
7
+ end
8
+
9
+ def self.search(search_query, options = {})
10
+ search_query = URI.escape(search_query)
11
+ params = {"stubhubDocumentType" => "#{demodulize(self).downcase}",
12
+ "description" => "#{search_query}"}
13
+ Client.make_request(Venue, params, options = {})
14
+ end
15
+
16
+ end
3
17
  end
@@ -1,3 +1,3 @@
1
1
  module Stubhub
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stubhub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-18 00:00:00.000000000 Z
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: HTTParty