tiqets 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac29b67471ebf800014817997928773e3bdc24e4
4
- data.tar.gz: bef1664acb0ba4cb5d629e78900aaed38b2c025a
3
+ metadata.gz: 58a9128f0eeb3fe9c16aa58845a7e4b718cbd323
4
+ data.tar.gz: d4a69be377f0f1466f6b18820ba2d47c74d3f23e
5
5
  SHA512:
6
- metadata.gz: b9b253f4b73bebdba922f294fbcfa8783d866dc2d7b1398f871bda2451ede7d216712cef716fbde1c93aaa109ab6d653b870caa8a8066d655fcd6cd7b28a7de4
7
- data.tar.gz: c9709204cfd16e40ad63ff658b60dbaa79294eeda39157df7f5e35d504cb29648966e069daae9d439291d9b38cfb9ecfbd4be7b768e9c494f04c8eda7b4a20d6
6
+ metadata.gz: 5ca4a3bac7a153c4564ecf7caac312aa03d8592903bb11dd187bceeec7592adeac112df59dcd81b20fab685a5486563a2c234eb0aac1d22db719af317e784465
7
+ data.tar.gz: 598997ab957416a90145790dc88a5944c45e83a382819a6d04a3ddd7bff2e7e0969fd6d4b9750e37e161532a38afb64ddae78751b5d7a514a7482131b09e0ca2
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard :minitest do
2
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
3
+ watch(%r{^test/.+_test\.rb$})
4
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
5
+ end
data/README.md CHANGED
@@ -1,8 +1,12 @@
1
- # Tiqets
1
+ # 🎢 Tiqets
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tiqets`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A simple (unofficial) Ruby wrapper for the [Tiqets](https://www.tiqets.com) [API](https://api.tiqets.com/v2/docs/).
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ [![Travis CI status](https://img.shields.io/travis/richardvenneman/tiqets.svg?style=flat-square)](https://travis-ci.org/richardvenneman/tiqets)
6
+ [![RubyGem](https://img.shields.io/gem/v/tiqets.svg?style=flat-square)](https://rubygems.org/gems/tiqets)
7
+
8
+
9
+ Full 100% API coverage is not a direct goal as we're primarily developing this for our needs at [CitySpotters](https://www.cityspotters.com). Pull requests are definitely welcome.
6
10
 
7
11
  ## Installation
8
12
 
@@ -22,7 +26,27 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ You must be in possession of a Tiqets API key. Use this key to initialize a new API client:
30
+
31
+ ```ruby
32
+ @client = Tiqets::Client.new(api_key: 'my-api-key')
33
+ ```
34
+
35
+ Alternatively you can set the `TIQETS_API_KEY` environment variable and use the shared API instance with:
36
+
37
+ ```ruby
38
+ @client = Tiqets.default_api
39
+ ```
40
+
41
+ ### Products
42
+
43
+ #### Get a single product
44
+ Finds a product by Product ID. Returns an object with the properties [described in the API documentation](https://api.tiqets.com/v2/docs/#the-product-object).
45
+
46
+ ```ruby
47
+ @client.find_product(973698)
48
+ # => #<Tiqets::Resources::Product::Product:0x007fe9c8438a00>
49
+ ```
26
50
 
27
51
  ## Contributing
28
52
 
data/lib/tiqets.rb CHANGED
@@ -1,5 +1,11 @@
1
+ require 'http'
2
+
1
3
  require 'tiqets/version'
4
+ require 'tiqets/client'
5
+ require 'tiqets/error'
2
6
 
3
7
  module Tiqets
4
- # Your code goes here...
8
+ def self.default_api
9
+ @default_api ||= Client.new(api_key: ENV.fetch('TIQETS_API_KEY'))
10
+ end
5
11
  end
@@ -0,0 +1,33 @@
1
+ require 'addressable/uri'
2
+
3
+ require 'tiqets/resources/product'
4
+
5
+ module Tiqets
6
+ class Client
7
+ include Resources::Product
8
+
9
+ V2_ROOT = 'https://api.tiqets.com/v2/'.freeze
10
+
11
+ def initialize(root: V2_ROOT, api_key:)
12
+ @root = root
13
+ @api_key = api_key
14
+ end
15
+
16
+ def connection
17
+ @connection ||= HTTP.auth("Authorization: Token #{@api_key}")
18
+ end
19
+
20
+ def get(url, response_key)
21
+ response = connection.get(@root + url)
22
+
23
+ handle_response(response, response_key)
24
+ end
25
+
26
+ def handle_response(response, response_key)
27
+ response = JSON.parse(response)
28
+ return response[response_key] if response['success'] == true
29
+
30
+ raise Error.new(response['status'], response['message'])
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ module Tiqets
2
+ class Error < Exception
3
+ attr_reader :code, :error
4
+
5
+ def initialize(code, error)
6
+ @code = code
7
+ @error = error
8
+
9
+ super(message)
10
+ end
11
+
12
+ def message
13
+ message = "Tiqets API Error: #{@error}"
14
+ message += " (code: #{@code})" unless @code.nil?
15
+ message
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ module Tiqets
2
+ module Resources
3
+ module Product
4
+ SLUG = 'products'.freeze
5
+
6
+ def find_product(id)
7
+ response = get("products/#{id}", 'product')
8
+ Product.new(response)
9
+ end
10
+
11
+ class Product
12
+ attr_reader :id, :language, :languages, :title, :tagline, :price,
13
+ :sale_status, :country_name, :country_id, :city_name,
14
+ :city_id, :tag_ids, :images, :ratings, :geolocation,
15
+ :distance, :venue, :product_url, :product_checkout_url
16
+
17
+ def initialize(attributes)
18
+ @id = attributes['id']
19
+ @language = attributes['language']
20
+ @languages = attributes['languages']
21
+ @title = attributes['title']
22
+ @tagline = attributes['tagline']
23
+ @price = attributes['price']
24
+ @sale_status = attributes['sale_status']
25
+ @country_name = attributes['country_name']
26
+ @country_id = attributes['country_id']
27
+ @city_name = attributes['city_name']
28
+ @city_id = attributes['city_id']
29
+ @tag_ids = attributes['tag_ids']
30
+ @images = attributes['images']
31
+ @ratings = attributes['ratings']
32
+ @geolocation = attributes['geolocation']
33
+ @distance = attributes['distance']
34
+ @venue = attributes['venue']
35
+ @product_url = attributes['product_url']
36
+ @product_checkout_url = attributes['product_checkout_url']
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Tiqets
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/tiqets.gemspec CHANGED
@@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
20
20
  end
21
21
  spec.require_paths = ['lib']
22
22
 
23
+ spec.add_runtime_dependency 'http', '~> 2'
24
+
23
25
  spec.add_development_dependency 'bundler', '~> 1.15'
26
+ spec.add_development_dependency 'guard', '~> 2'
27
+ spec.add_development_dependency 'guard-minitest', '~> 2'
24
28
  spec.add_development_dependency 'rake', '~> 10.0'
25
- spec.add_development_dependency 'minitest', '~> 5.0'
29
+ spec.add_development_dependency 'webmock', '~> 3.0'
26
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiqets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Venneman
@@ -10,6 +10,20 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2017-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,34 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.15'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
@@ -39,19 +81,19 @@ dependencies:
39
81
  - !ruby/object:Gem::Version
40
82
  version: '10.0'
41
83
  - !ruby/object:Gem::Dependency
42
- name: minitest
84
+ name: webmock
43
85
  requirement: !ruby/object:Gem::Requirement
44
86
  requirements:
45
87
  - - "~>"
46
88
  - !ruby/object:Gem::Version
47
- version: '5.0'
89
+ version: '3.0'
48
90
  type: :development
49
91
  prerelease: false
50
92
  version_requirements: !ruby/object:Gem::Requirement
51
93
  requirements:
52
94
  - - "~>"
53
95
  - !ruby/object:Gem::Version
54
- version: '5.0'
96
+ version: '3.0'
55
97
  description: Ruby Tiqets API wrapper.
56
98
  email:
57
99
  - richardvenneman@me.com
@@ -63,12 +105,16 @@ files:
63
105
  - ".ruby-version"
64
106
  - ".travis.yml"
65
107
  - Gemfile
108
+ - Guardfile
66
109
  - LICENSE.txt
67
110
  - README.md
68
111
  - Rakefile
69
112
  - bin/console
70
113
  - bin/setup
71
114
  - lib/tiqets.rb
115
+ - lib/tiqets/client.rb
116
+ - lib/tiqets/error.rb
117
+ - lib/tiqets/resources/product.rb
72
118
  - lib/tiqets/version.rb
73
119
  - tiqets.gemspec
74
120
  homepage: https://github.com/richardvenneman/tiqets