brownpapertickets 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/brownpapertickets.rb +1 -0
- data/lib/brownpapertickets/base.rb +5 -1
- data/lib/brownpapertickets/orderlist.rb +142 -0
- data/lib/brownpapertickets/version.rb +1 -1
- metadata +4 -3
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.7
|
data/lib/brownpapertickets.rb
CHANGED
@@ -5,6 +5,7 @@ require File.join(File.dirname(__FILE__), 'brownpapertickets/base')
|
|
5
5
|
require File.join(File.dirname(__FILE__), 'brownpapertickets/event')
|
6
6
|
require File.join(File.dirname(__FILE__), 'brownpapertickets/date')
|
7
7
|
require File.join(File.dirname(__FILE__), 'brownpapertickets/price')
|
8
|
+
require File.join(File.dirname(__FILE__), 'brownpapertickets/orderlist')
|
8
9
|
require File.join(File.dirname(__FILE__), 'brownpapertickets/httpost')
|
9
10
|
module BrownPaperTickets
|
10
11
|
|
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
module BrownPaperTickets
|
10
10
|
class Base
|
11
|
-
attr_reader :id, :account, :event, :date, :price
|
11
|
+
attr_reader :id, :account, :event, :date, :price, :orderlist
|
12
12
|
|
13
13
|
# Needs the brownpapersticker's credentials (id and account),
|
14
14
|
# creates a new instance of event, date and price
|
@@ -20,6 +20,7 @@ module BrownPaperTickets
|
|
20
20
|
@event = BrownPaperTickets::Event.new(self.id, self.account)
|
21
21
|
@date = BrownPaperTickets::Date.new(self.id, self.account)
|
22
22
|
@price = BrownPaperTickets::Price.new(self.id, self.account)
|
23
|
+
@orderlist = BrownPaperTickets::Orderlist.new(self.id, self.account)
|
23
24
|
end
|
24
25
|
|
25
26
|
# Returns the event
|
@@ -34,6 +35,9 @@ module BrownPaperTickets
|
|
34
35
|
def prices
|
35
36
|
@price
|
36
37
|
end
|
38
|
+
def orderlists
|
39
|
+
@orderlist
|
40
|
+
end
|
37
41
|
end
|
38
42
|
|
39
43
|
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'hpricot'
|
2
|
+
module BrownPaperTickets
|
3
|
+
class Orderlist
|
4
|
+
include HTTParty
|
5
|
+
base_uri "https://www.brownpapertickets.com/api2"
|
6
|
+
|
7
|
+
attr_reader :attributes, :server_response
|
8
|
+
|
9
|
+
REQUIRED_ATTR=["date_id", "price_id", "event_id"]
|
10
|
+
|
11
|
+
ATTRS=["event_id", "date_id", "price_id"]
|
12
|
+
|
13
|
+
def initialize(id, account, attributes={})
|
14
|
+
@@id = id
|
15
|
+
@@account = account
|
16
|
+
@attributes = attributes
|
17
|
+
end
|
18
|
+
|
19
|
+
def new(params={})
|
20
|
+
Event.new(@@id,@@account, params, event_id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_missing(m, *args, &block)
|
24
|
+
if ATTRS.include?(m.to_s.gsub("=",""))
|
25
|
+
if m.to_s.include?("=")
|
26
|
+
self.attributes[m.to_s.gsub("=","")] = *args.to_s
|
27
|
+
else
|
28
|
+
result = self.attributes[m.to_s]
|
29
|
+
end
|
30
|
+
else
|
31
|
+
raise NoMethodError.new("Method missing #{m}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def validates_required_attr
|
36
|
+
missing_field = []
|
37
|
+
REQUIRED_ATTR.each do |attr|
|
38
|
+
missing_field << attr if self.send(attr,nil,nil).blank?
|
39
|
+
end
|
40
|
+
unless missing_field.blank?
|
41
|
+
@server_response = "The following attributes are missing:"
|
42
|
+
missing_field.each{|att| @server_response = @server_response + " " + att }
|
43
|
+
return false
|
44
|
+
end
|
45
|
+
return true
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_report
|
49
|
+
body = {"id" => @@id, "account" => @@account, "event_id" => event_id, "date_id"=>date_id, "price_id" => price_id}
|
50
|
+
query = self.attributes.merge("id" => @@id, "account" => @@account,"event_id" => event_id, "date_id"=>date_id, "price_id" => price_id )
|
51
|
+
response = BrownPaperTickets::Httpost.new(Net::HTTP::Get, "https://www.brownpapertickets.com/api2/orderlist",:query => query)
|
52
|
+
response.options[:body] = query
|
53
|
+
st = response.perform
|
54
|
+
xml = Hpricot(st.response.body)
|
55
|
+
p xml
|
56
|
+
end
|
57
|
+
|
58
|
+
def create(params={})
|
59
|
+
date = Event.new(@@id,@@account, params)
|
60
|
+
date.save!
|
61
|
+
end
|
62
|
+
|
63
|
+
# resultcode
|
64
|
+
# 300055 - Required variables are missing
|
65
|
+
# 300056 - Unknown error
|
66
|
+
# 300057 - Unable to find event
|
67
|
+
# 300058 - Event does not belong to account
|
68
|
+
# 300059 - Unknown error
|
69
|
+
# 300060 - Unable to find date
|
70
|
+
# 300061 - Required variables are missing
|
71
|
+
# 300062 - Unable to update date
|
72
|
+
# 000000 - Success
|
73
|
+
|
74
|
+
|
75
|
+
def process_update_response(response)
|
76
|
+
case response
|
77
|
+
when "000000" then
|
78
|
+
@server_response = "Success"
|
79
|
+
return true
|
80
|
+
when "300055" then
|
81
|
+
@server_response = "Required variables are missing"
|
82
|
+
return false
|
83
|
+
when "300056" then
|
84
|
+
@server_response = "Unknown error"
|
85
|
+
return false
|
86
|
+
when "300057" then
|
87
|
+
@server_response = "Unable to find event"
|
88
|
+
return false
|
89
|
+
when "300058" then
|
90
|
+
@server_response = "Event does not belong to account"
|
91
|
+
return false
|
92
|
+
when "300059" then
|
93
|
+
@server_response = "Unknown error"
|
94
|
+
return false
|
95
|
+
when "300060" then
|
96
|
+
@server_response = "Unable to find date"
|
97
|
+
return false
|
98
|
+
when "300061" then
|
99
|
+
@server_response = "Required variables are missing"
|
100
|
+
return false
|
101
|
+
when "300062" then
|
102
|
+
@server_response = "Unable to update date"
|
103
|
+
return false
|
104
|
+
else
|
105
|
+
@server_response = "Unknown error"
|
106
|
+
return false
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def process_create_response(response, event_id)
|
111
|
+
case response
|
112
|
+
when "0000" then
|
113
|
+
self.date_id = date_id
|
114
|
+
@server_response = "success"
|
115
|
+
return true
|
116
|
+
when "300038" then
|
117
|
+
@server_response = "Required variables are missing"
|
118
|
+
return false
|
119
|
+
when "300039" then
|
120
|
+
@server_response = "Unknown error while posting info to DB"
|
121
|
+
return false
|
122
|
+
when "300040" then
|
123
|
+
@server_response = "Event does not belong to user"
|
124
|
+
return false
|
125
|
+
when "300041" then
|
126
|
+
@server_response = "Unable to add date"
|
127
|
+
return false
|
128
|
+
else
|
129
|
+
@server_response = "Unknown error"
|
130
|
+
return false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def server_response
|
135
|
+
@server_response
|
136
|
+
end
|
137
|
+
|
138
|
+
def attributes
|
139
|
+
@attributes
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brownpapertickets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alvaro Insignares
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/brownpapertickets/date.rb
|
115
115
|
- lib/brownpapertickets/event.rb
|
116
116
|
- lib/brownpapertickets/httpost.rb
|
117
|
+
- lib/brownpapertickets/orderlist.rb
|
117
118
|
- lib/brownpapertickets/price.rb
|
118
119
|
- lib/brownpapertickets/version.rb
|
119
120
|
- lib/brownpapertickets/xmlparse.rb
|