ticketfly-api 0.1.0 → 0.2.0

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.
@@ -1,11 +1,16 @@
1
1
  = ticketfly-api
2
2
 
3
3
  ~/code/ticketfly/ticketfly-api$ irb
4
- 1.9.3-p0 :001 > require 'ticketfly-api'
4
+ 1.9.3p0 :001 > require 'ticketfly-api'
5
5
  => true
6
- 1.9.3-p0 :002 > TicketflyApi::Base.hello_world
7
- Hello World!
8
- => nil
6
+ 1.9.3p0 :002 > t = TicketflyApi::Base.new
7
+ => #<TicketflyApi::Base:0x007f96d90afba0 @errors=[]>
8
+ 1.9.3p0 :003 > t.event_show(91275)
9
+ => #<TicketflyApi::Event [:id => 91275, :name => Papercuts, Sonny and the Sunsets]>
10
+ 1.9.3p0 :004 > event = t.event_show(91275)
11
+ => #<TicketflyApi::Event [:id => 91275, :name => Papercuts, Sonny and the Sunsets]>
12
+ 1.9.3p0 :005 > event.name
13
+ => "Papercuts, Sonny and the Sunsets"
9
14
 
10
15
  == Contributing to ticketfly-api
11
16
 
@@ -1,7 +1,13 @@
1
+ require 'httparty'
2
+ require 'ticketfly-api/exceptions'
3
+
4
+ require 'ticketfly-api/hash_based_store'
5
+ require 'ticketfly-api/event'
6
+
1
7
  module TicketflyApi
2
- class Base
3
- def self.hello_world
4
- puts "Hello World!"
5
- end
6
- end
7
- end
8
+ #everything now in independent class files
9
+ end
10
+
11
+ #classes to perform network access to Strava
12
+ require 'ticketfly-api/events'
13
+ require 'ticketfly-api/base'
@@ -0,0 +1,36 @@
1
+ YAML::ENGINE.yamler = "syck"
2
+
3
+ module TicketflyApi
4
+ class Base
5
+ include HTTParty
6
+
7
+ include TicketflyApi::Events
8
+
9
+ default_params :output => 'json'
10
+ format :json
11
+ base_uri 'https://api-stage.ticketfly.com/v2/purchase'
12
+
13
+ attr_reader :errors
14
+
15
+ def initialize
16
+ @errors = []
17
+ end
18
+
19
+ def call(command, options)
20
+ begin
21
+ result = self.class.get("/#{command}", :query => options)
22
+ rescue HTTParty::UnsupportedFormat, HTTParty::UnsupportedURIScheme, HTTParty::ResponseError, HTTParty::RedirectionTooDeep
23
+ raise NetworkError.new
24
+ end
25
+
26
+ if result && result.parsed_response == "<html><body><h1>500 Internal Server Error</h1></body></html>"
27
+ @errors << "Ticketfly returned a 500 error"
28
+ raise CommandError.new
29
+ end
30
+
31
+ @errors << result["error"] if result && result["error"]
32
+ raise InvalidResponseError.new if result.nil? || !result["error"].blank?
33
+ result
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module TicketflyApi
2
+ class Event < HashBasedStore
3
+ ATTRIBUTE_MAP = {'id' => :id, 'name' => :name}
4
+ def initialize(connection, options = {})
5
+ super(connection, ATTRIBUTE_MAP, {}, options)
6
+ end
7
+
8
+ def show
9
+ self.merge(@connection.event_show(self.id))
10
+ self
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module TicketflyApi
2
+ module Events
3
+ def event_show(id)
4
+ result = call("event/#{id}", {})
5
+ Event.new(self, result)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ module TicketflyApi
2
+ class InvalidResponseError < StandardError; end
3
+
4
+ class CommandError < StandardError; end
5
+
6
+ class NetworkError < StandardError; end
7
+
8
+ class InternalError < StandardError; end
9
+ end
@@ -0,0 +1,52 @@
1
+ module TicketflyApi
2
+ class HashBasedStore
3
+ def initialize(connection, attribute_map, nested_class_map, options)
4
+ @connection = connection
5
+ @valid_attributes = attribute_map
6
+ @nested_class_map = nested_class_map
7
+
8
+ @values = {}
9
+ @valid_attributes.each do |json_key, ruby_key|
10
+ value = options[json_key]
11
+ @values[ruby_key] = value.is_a?(Hash) ? @nested_class_map[ruby_key].new(@connection, value) : value
12
+ end
13
+ end
14
+
15
+ def [](key)
16
+ @values[key]
17
+ end
18
+
19
+ #This needs to be explicit because otherwise you get the Object#id method (which is depreciated) rather than
20
+ #method missing getting called
21
+ def id
22
+ @values[:id]
23
+ end
24
+
25
+ def to_s
26
+ result = []
27
+ @values.each do |key, value|
28
+ result << ":#{key} => #{value}" if value
29
+ end
30
+
31
+ "#<#{self.class} [#{result.join(', ')}]>"
32
+ end
33
+
34
+ #cleanup how StravaApi objects are displayed in irb
35
+ alias_method :original_inspect, :inspect
36
+ alias_method :inspect, :to_s
37
+
38
+ def merge(other)
39
+ @valid_attributes.each do |json_key, ruby_key|
40
+ @values[ruby_key] = other[ruby_key] if other[ruby_key]
41
+ end
42
+ end
43
+
44
+ def method_missing(symbol, *args)
45
+ if @valid_attributes.values.include?(symbol)
46
+ @values[symbol]
47
+ else
48
+ raise InternalError
49
+ end
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketfly-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-11 00:00:00.000000000 Z
12
+ date: 2012-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: &70324482071880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70324482071880
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: shoulda
16
- requirement: &70123557939060 !ruby/object:Gem::Requirement
27
+ requirement: &70324482069860 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
@@ -21,10 +32,10 @@ dependencies:
21
32
  version: '0'
22
33
  type: :development
23
34
  prerelease: false
24
- version_requirements: *70123557939060
35
+ version_requirements: *70324482069860
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rdoc
27
- requirement: &70123557953880 !ruby/object:Gem::Requirement
38
+ requirement: &70324482069020 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ~>
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '3.12'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70123557953880
46
+ version_requirements: *70324482069020
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: bundler
38
- requirement: &70123557950980 !ruby/object:Gem::Requirement
49
+ requirement: &70324482067740 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ~>
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: 1.0.0
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70123557950980
57
+ version_requirements: *70324482067740
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: jeweler
49
- requirement: &70123557948020 !ruby/object:Gem::Requirement
60
+ requirement: &70324482066820 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ~>
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: 1.8.3
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70123557948020
68
+ version_requirements: *70324482066820
58
69
  description: Ticketfly API
59
70
  email: leoromanovsky@gmail.com
60
71
  executables: []
@@ -63,14 +74,14 @@ extra_rdoc_files:
63
74
  - LICENSE.txt
64
75
  - README.rdoc
65
76
  files:
66
- - .document
67
- - Gemfile
68
- - Gemfile.lock
77
+ - lib/ticketfly-api.rb
78
+ - lib/ticketfly-api/base.rb
79
+ - lib/ticketfly-api/event.rb
80
+ - lib/ticketfly-api/events.rb
81
+ - lib/ticketfly-api/exceptions.rb
82
+ - lib/ticketfly-api/hash_based_store.rb
69
83
  - LICENSE.txt
70
84
  - README.rdoc
71
- - Rakefile
72
- - VERSION
73
- - lib/ticketfly-api.rb
74
85
  homepage: http://github.com/leoromanovsky/ticketfly-api
75
86
  licenses:
76
87
  - MIT
@@ -86,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
97
  version: '0'
87
98
  segments:
88
99
  - 0
89
- hash: -2930718481104823363
100
+ hash: 2209704427804474697
90
101
  required_rubygems_version: !ruby/object:Gem::Requirement
91
102
  none: false
92
103
  requirements:
data/.document DELETED
@@ -1,5 +0,0 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
data/Gemfile DELETED
@@ -1,13 +0,0 @@
1
- source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
5
-
6
- # Add dependencies to develop your gem here.
7
- # Include everything needed to run rake, tests, features, etc.
8
- group :development do
9
- gem "shoulda", ">= 0"
10
- gem "rdoc", "~> 3.12"
11
- gem "bundler", "~> 1.0.0"
12
- gem "jeweler", "~> 1.8.3"
13
- end
@@ -1,23 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- git (1.2.5)
5
- jeweler (1.8.3)
6
- bundler (~> 1.0)
7
- git (>= 1.2.5)
8
- rake
9
- rdoc
10
- json (1.6.5)
11
- rake (0.9.2.2)
12
- rdoc (3.12)
13
- json (~> 1.4)
14
- shoulda (2.11.3)
15
-
16
- PLATFORMS
17
- ruby
18
-
19
- DEPENDENCIES
20
- bundler (~> 1.0.0)
21
- jeweler (~> 1.8.3)
22
- rdoc (~> 3.12)
23
- shoulda
data/Rakefile DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
5
- begin
6
- Bundler.setup(:default, :development)
7
- rescue Bundler::BundlerError => e
8
- $stderr.puts e.message
9
- $stderr.puts "Run `bundle install` to install missing gems"
10
- exit e.status_code
11
- end
12
- require 'rake'
13
-
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "ticketfly-api"
18
- gem.homepage = "http://github.com/leoromanovsky/ticketfly-api"
19
- gem.license = "MIT"
20
- gem.summary = "Ticketfly API"
21
- gem.description = "Ticketfly API"
22
- gem.email = "leoromanovsky@gmail.com"
23
- gem.authors = ["Leo Romanovsky"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
- require 'rake/testtask'
29
- Rake::TestTask.new(:test) do |test|
30
- test.libs << 'lib' << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
-
35
- task :default => :test
36
-
37
- require 'rdoc/task'
38
- Rake::RDocTask.new do |rdoc|
39
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
-
41
- rdoc.rdoc_dir = 'rdoc'
42
- rdoc.title = "ticketfly-api #{version}"
43
- rdoc.rdoc_files.include('README*')
44
- rdoc.rdoc_files.include('lib/**/*.rb')
45
- end
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0