brownpapertickets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Alvaro Insignares
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/README ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = brownpapertickets
2
+
3
+ Brownpapertickests gem, is a wrapper for Brownpapertickests's service.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Alvaro Insignares. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "brownpapertickets"
8
+ gem.summary = "Brown Paper tickets API wrapper"
9
+ gem.description = "Brown Paper tickets API wrapper"
10
+ gem.email = ["alvaro@koombea.com", "niyireth.delahoz@koombea.com"]
11
+ gem.homepage = "http://github.com/niyireth/brownpapertickets"
12
+ gem.authors = ["Alvaro Insignares", "Niyireth De La Hoz"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "fakeweb", "~> 1.2.0"
15
+ gem.add_dependency "httparty", ">=0.6.1"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "brownpapertickets #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,79 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{brownpapertickets}
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alvaro Insignares"]
12
+ s.date = %q{2011-02-16}
13
+ s.description = %q{Brown Paper tickets API wrapper}
14
+ s.email = %q{alvaro@koombea.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "README",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "brownpapertickets/.document",
26
+ "brownpapertickets/.gitignore",
27
+ "examples/create_item.rb",
28
+ "examples/fetch_items.rb",
29
+ "examples/update_item.rb",
30
+ "lib/brownpapertickets.rb",
31
+ "lib/brownpapertickets/base.rb",
32
+ "lib/brownpapertickets/date.rb",
33
+ "lib/brownpapertickets/price.rb",
34
+ "lib/brownpapertickets/event.rb",
35
+ "lib/brownpapertickets/httpost.rb",
36
+ "lib/brownpapertickets/xmlparse.rb",
37
+ "spec/brownpapertickets_spec.rb",
38
+ "spec/fixtures/all_events.xml",
39
+ "spec/fixtures/create_not_ok.xml",
40
+ "spec/fixtures/create_ok.xml",
41
+ "spec/fixtures/event.xml",
42
+ "spec/fixtures/test.json",
43
+ "spec/fixtures/update_not_ok.xml",
44
+ "spec/fixtures/update_ok.xml",
45
+ "spec/spec.opts",
46
+ "spec/spec_helper.rb"
47
+ ]
48
+ s.homepage = %q{http://github.com/bbto/brownpapertickets}
49
+ s.require_paths = ["lib"]
50
+ s.rubygems_version = %q{1.3.7}
51
+ s.summary = %q{Brown Paper tickets API wrapper}
52
+ s.test_files = [
53
+ "examples/create_item.rb",
54
+ "examples/fetch_items.rb",
55
+ "examples/update_item.rb",
56
+ "spec/brownpapertickets_spec.rb",
57
+ "spec/spec_helper.rb"
58
+ ]
59
+
60
+ if s.respond_to? :specification_version then
61
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
+ s.specification_version = 3
63
+
64
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
65
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
66
+ s.add_development_dependency(%q<fakeweb>, ["~> 1.2.0"])
67
+ s.add_runtime_dependency(%q<httparty>, [">= 0.6.1"])
68
+ else
69
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
70
+ s.add_dependency(%q<fakeweb>, ["~> 1.2.0"])
71
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
72
+ end
73
+ else
74
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
75
+ s.add_dependency(%q<fakeweb>, ["~> 1.2.0"])
76
+ s.add_dependency(%q<httparty>, [">= 0.6.1"])
77
+ end
78
+ end
79
+
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'brownpapertickets')
2
+
3
+ @valid_attributes = {
4
+ :account => "citizen_client",
5
+ :id => "XsIhXp7K8CknZsC"
6
+ }
7
+ @bpt = BrownPaperTickets::Base.new(@valid_attributes[:id],@valid_attributes[:account])
8
+
9
+ event = @bpt.events.new()
10
+ # e_name - This is the name of the event.
11
+ # e_city - This is the city in which the event is located.
12
+ # e_state - This is the state in which the event is located.
13
+ # e_short_description - This is the short description for the event. Must contain less than 250 characters.
14
+ # e_description - This is the full description for the event.
15
+ #["e_name","e_city","e_state", "e_short_description", "e_description","e_address1","e_address2","e_zip","e_phone","e_web","end_of_event_message",
16
+ # "end_of_sale_message","date_notes","e_notes","keywords","c_name","c_email","c_phone","c_fax","c_address1","c_address2","c_city","c_state","c_zip",
17
+ # "c_country","public", "title","link", "description", "event_id"]
18
+ event.e_zip = "90210"
19
+ event.e_name = "Test Event"
20
+ event.e_city = "Beverly Hills"
21
+ event.e_state = "CA"
22
+ event.e_short_description = " this is a test"
23
+ event.e_description = "this is a test"
24
+ event.save!
25
+ puts "New Event: #{event.event_id}"
26
+ puts event.validates_required_attr
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'brownpapertickets')
2
+
3
+ @valid_attributes = {
4
+ :account => "citizen_client",
5
+ :id => "XsIhXp7K8CknZsC"
6
+ }
7
+ @bpt = BrownPaperTickets::Base.new(@valid_attributes[:id],@valid_attributes[:account])
8
+
9
+ event = @bpt.events.find(106861)
10
+
11
+ puts "Title: #{event.title}"
12
+ puts "Event id: #{event.event_id}"
13
+ puts "E zip: #{event.e_zip}"
14
+
15
+ event.e_zip = "hola"
16
+ puts "Live: #{event.live}"
17
+
18
+
19
+ puts "E zip: #{event.e_zip}"
20
+ puts "fetching all... this could take a while ..."
21
+
22
+ events = @bpt.events.all
23
+
24
+ puts "this is the result:"
25
+ event = events.first
26
+
27
+ puts "Title: #{event.title}"
28
+ puts "Event id: #{event.event_id}"
29
+ puts "E zip: #{event.e_zip}"
30
+
31
+ event = events.last
32
+ puts "Title: #{event.title}"
33
+ puts "Event id: #{event.event_id}"
34
+ puts "E zip: #{event.e_zip}"
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'brownpapertickets')
2
+
3
+ @valid_attributes = {
4
+ :account => "citizen_client",
5
+ :id => "XsIhXp7K8CknZsC"
6
+ }
7
+ @bpt = BrownPaperTickets::Base.new(@valid_attributes[:id],@valid_attributes[:account])
8
+
9
+ event = @bpt.events.find(120405)
10
+
11
+ event.update_attribute(:e_name, "This Awsome Title")
12
+
13
+ puts "*"*100
14
+ puts event.e_name
15
+ puts "*"*100
16
+
17
+ puts event.server_response
18
+
19
+ event.update_attributes({:e_name => "This Awsome Title2",:e_address1 => "Evergreen av 123", :e_phone => "5553335588"})
20
+
21
+ puts "*"*100
22
+ puts event.e_name
23
+ puts event.e_address1
24
+ puts event.e_phone
25
+ puts "*"*100
26
+
27
+ puts event.server_response
28
+
29
+ event.e_name = "This Super Awsome Title2"
30
+ event.e_address1 = "Evergreen av 123 nxt to homer"
31
+ event.e_phone = "2365476235"
32
+
33
+ puts event.save!
34
+
35
+ puts "*"*100
36
+ puts event.e_name
37
+ puts event.e_address1
38
+ puts event.e_phone
39
+ puts "*"*100
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'open-uri'
4
+ require File.join(File.dirname(__FILE__), 'brownpapertickets/base')
5
+ require File.join(File.dirname(__FILE__), 'brownpapertickets/event')
6
+ require File.join(File.dirname(__FILE__), 'brownpapertickets/date')
7
+ require File.join(File.dirname(__FILE__), 'brownpapertickets/price')
8
+ require File.join(File.dirname(__FILE__), 'brownpapertickets/httpost')
9
+ module BrownPaperTickets
10
+
11
+ end
@@ -0,0 +1,26 @@
1
+ module BrownPaperTickets
2
+ class Base
3
+ attr_reader :id, :account, :event, :date, :price
4
+
5
+ def initialize(id, account)
6
+ @id = id
7
+ @account = account
8
+ raise ArgumentError.new("id should not be nil") if @id.nil?
9
+ raise ArgumentError.new("account should not be nil") if @account.nil?
10
+ @event = BrownPaperTickets::Event.new(self.id, self.account)
11
+ @date = BrownPaperTickets::Date.new(self.id, self.account)
12
+ @price = BrownPaperTickets::Price.new(self.id, self.account)
13
+ end
14
+
15
+ def events
16
+ @event
17
+ end
18
+ def dates
19
+ @date
20
+ end
21
+ def prices
22
+ @price
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,228 @@
1
+ require 'hpricot'
2
+ module BrownPaperTickets
3
+ class Date
4
+ include HTTParty
5
+ base_uri "https://www.brownpapertickets.com/api2"
6
+
7
+ attr_reader :attributes, :server_response
8
+
9
+ REQUIRED_ATTR=["begin_time", "end_time", "sales_end", "max_sales"]
10
+
11
+ ATTRS=["begin_time", "end_time", "event_id", "date_id", "sales_end", "max_sales"]
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 all
24
+ dates = Event.get("/datelist", :query =>{"id" => @@id , "account" => @@account})
25
+ parsed_date = []
26
+ date.parsed_response["document"]["date"].each do |date|
27
+ parsed_date << Event.new(@id,@account, date)
28
+ end
29
+ return parsed_event
30
+ end
31
+
32
+ def find(event_id)
33
+ date = Event.get("/datelist",:query =>{"id" => @@id , "account" => @@account, "event_id" => event_id, "date_id"=>date_id})
34
+ @attributes = event.parsed_response["document"]["date"]
35
+ return self
36
+ end
37
+
38
+ def method_missing(m, *args, &block)
39
+ if ATTRS.include?(m.to_s.gsub("=",""))
40
+ if m.to_s.include?("=")
41
+ self.attributes[m.to_s.gsub("=","")] = *args.to_s
42
+ else
43
+ result = self.attributes[m.to_s]
44
+ end
45
+ else
46
+ raise NoMethodError.new("Method missing #{m}")
47
+ end
48
+ end
49
+
50
+ def validates_required_attr
51
+ missing_field = []
52
+ REQUIRED_ATTR.each do |attr|
53
+ missing_field << attr if self.send(attr,nil,nil).blank?
54
+ end
55
+ unless missing_field.blank?
56
+ @server_response = "The following attributes are missing:"
57
+ missing_field.each{|att| @server_response = @server_response + " " + att }
58
+ return false
59
+ end
60
+ return true
61
+ end
62
+
63
+ # Response while saving
64
+ # 300036 - Required variables are missing
65
+ # 300037 - Unknown error while posting info to DB
66
+ # 000000 - Success
67
+
68
+ def save!
69
+ if self.date_id.blank?
70
+ #changeevent
71
+ return false unless validates_required_attr
72
+ new_save("adddate")
73
+ else
74
+ #createevent
75
+ new_save("changedate")
76
+ end
77
+ end
78
+
79
+ def new_save(param)
80
+ body = {"id" => @@id, "account" => @@account, "event_id" => event_id}
81
+ query = self.attributes.merge("id" => @@id, "account" => @@account)
82
+ response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/#{param}",:query => query)
83
+ response.options[:body] = query
84
+ st = response.perform
85
+ xml = Hpricot(st.response.body)
86
+ if param == "adddate"
87
+ p "algo"*12
88
+ self.date_id = (xml/:date_id).inner_html if (xml/:resultcode).inner_html == "000000"
89
+ process_create_response( (xml/:resultcode).inner_html, date_id)
90
+ p date_id
91
+ p event_id
92
+ else
93
+ process_update_response( (xml/:resultcode).inner_html)
94
+ end
95
+ end
96
+
97
+ def create(params={})
98
+ date = Event.new(@@id,@@account, params)
99
+ date.save!
100
+ end
101
+
102
+ def live
103
+ return true if self.attributes["live"] == "y"
104
+ return false
105
+ end
106
+
107
+ def live=(param)
108
+ if param
109
+ self.attributes["live"] = "y"
110
+ else
111
+ self.attributes["live"] = "f"
112
+ end
113
+ end
114
+
115
+ def public
116
+ return true if self.attributes["public"] == "t"
117
+ return false
118
+ end
119
+
120
+ def public=(param)
121
+ if param
122
+ self.attributes["public"] = "t"
123
+ else
124
+ self.attributes["public"] = "n"
125
+ end
126
+ end
127
+
128
+ # resultcode
129
+ # 300049 - Required variables are missing
130
+ # 300050 - Unknown error
131
+ # 300051 - Unable to find event
132
+ # 300052 - Event does not belong to account
133
+ # 300053 - Required variables are missing
134
+ # 300054 - Unable to update event
135
+ # 000000 - Success
136
+
137
+ def update_attribute(key, value)
138
+ assign = key.to_s + "="
139
+ self.send(assign,value)
140
+ query = {"id" => @@id, "account" => @@account, key.to_s => value, "event_id" => self.event_id}
141
+ response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/changedate",:query => query)
142
+ response.options[:body] = query
143
+ st = response.perform
144
+ xml = Hpricot(st.response.body)
145
+ return process_update_response((xml/:resultcode).inner_html)
146
+ end
147
+
148
+ def update_attributes(params)
149
+ params.each do |key, value|
150
+ assign = key.to_s + "="
151
+ self.send(assign,value)
152
+ end
153
+ query = {"id" => @@id, "account" => @@account, "event_id" => self.event_id}.merge(params)
154
+ response = BrownPaperTickets::Httpost.new(Net::HTTP::Post, "https://www.brownpapertickets.com/api2/changedate",:query => query)
155
+ response.options[:body] = query
156
+ st = response.perform
157
+ xml = Hpricot(st.response.body)
158
+ return process_update_response((xml/:resultcode).inner_html)
159
+ end
160
+
161
+ def process_update_response(response)
162
+ case response
163
+ when "000000" then
164
+ @server_response = "Success"
165
+ return true
166
+ when "300055" then
167
+ @server_response = "Required variables are missing"
168
+ return false
169
+ when "300056" then
170
+ @server_response = "Unknown error"
171
+ return false
172
+ when "300057" then
173
+ @server_response = "Unable to find event"
174
+ return false
175
+ when "300058" then
176
+ @server_response = "Event does not belong to account"
177
+ return false
178
+ when "300059" then
179
+ @server_response = "Unknown error"
180
+ return false
181
+ when "300060" then
182
+ @server_response = "Unable to find date"
183
+ return false
184
+ when "300061" then
185
+ @server_response = "Required variables are missing"
186
+ return false
187
+ when "300062" then
188
+ @server_response = "Unable to update date"
189
+ return false
190
+ else
191
+ @server_response = "Unknown error"
192
+ return false
193
+ end
194
+ end
195
+
196
+ def process_create_response(response, event_id)
197
+ case response
198
+ when "0000" then
199
+ self.event_id = event_id
200
+ @server_response = "success"
201
+ return true
202
+ when "300038" then
203
+ @server_response = "Required variables are missing"
204
+ return false
205
+ when "300039" then
206
+ @server_response = "Unknown error while posting info to DB"
207
+ return false
208
+ when "300040" then
209
+ @server_response = "Event does not belong to user"
210
+ return false
211
+ when "300041" then
212
+ @server_response = "Unable to add date"
213
+ return false
214
+ else
215
+ @server_response = "Unknown error"
216
+ return false
217
+ end
218
+ end
219
+
220
+ def server_response
221
+ @server_response
222
+ end
223
+
224
+ def attributes
225
+ @attributes
226
+ end
227
+ end
228
+ end