stub_hub_api 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f87144cbbc215abaaa8630e6bdb64777eab7789
4
+ data.tar.gz: 3e5fc4976034571c5235dd21cdd28baa067bc025
5
+ SHA512:
6
+ metadata.gz: b8302a1e10fd72d0f3916379af73f5e33eb49e9384d8e703468ac2c23178a937807435b67a8714b8c4b6e69364baa1ef97c87f59c1811507e8b6c56c5c113fe5
7
+ data.tar.gz: 32e5094aef82501b444b25cc6c921d96963112a85cfbb7a698d65df2695ed0a2ac9fb421501b36180927602413a95d0671e797bb01ed7183c989627089a13ce0
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in stub_hub_api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 chebyte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # StubHubApi [![Code Climate](https://codeclimate.com/github/hashdog/stub_hub_api/badges/gpa.svg)](https://codeclimate.com/github/hashdog/stub_hub_api)
2
+
3
+ This gem provides access to add, edit and delete listings appearing on StubHub.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'stub_hub_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install stub_hub_api
18
+
19
+ ## Usage
20
+
21
+ ### Get credentials account
22
+
23
+ client = StubHubApi::Login.new(consumer_key: 'consumer_key',
24
+ consumer_secret: 'consumer_secret',
25
+ username: 'username',
26
+ password: 'password')
27
+
28
+ client.account
29
+ client.user_id
30
+
31
+ ### Account Management
32
+ client = StubHubApi::AccountManagement.new("token")
33
+ client.get_listing('user_id', options)
34
+ client.get_listings('user_id')
35
+
36
+ ### Account Management Sales
37
+ client = StubHubApi::AccountManagementSale.new("token")
38
+ client.get_sales(user_id, options)
39
+
40
+ ### Listing
41
+ client = StubHubApi::Listing.new("token")
42
+ client.create(options)
43
+ client.create_with_barcode(options)
44
+ client.delete(listing_id)
45
+ client.update(listing_id, options)
46
+ client.show(listing_id, options)
47
+
48
+ ### Search
49
+ client = StubHubApi::Search.new("token")
50
+ client.listing(options)
51
+ client.section(options)
52
+ client.event(options)
53
+
54
+ ### Alerts
55
+ client = StubHubApi::Alert.new("token")
56
+ client.delete(user_id, alert_id)
57
+ client.update(user_id, options)
58
+ client.show(user_id, alert_id, options)
59
+
60
+
61
+ ## Contributing
62
+
63
+ 1. Fork it ( https://github.com/hashdog/stub_hub_api/fork )
64
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
65
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
66
+ 4. Push to the branch (`git push origin my-new-feature`)
67
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,16 @@
1
+ require 'json'
2
+ require 'faraday'
3
+
4
+ require_relative 'stub_hub_api/version'
5
+ require_relative 'stub_hub_api/response'
6
+ require_relative 'stub_hub_api/base'
7
+ require_relative 'stub_hub_api/login'
8
+ require_relative 'stub_hub_api/account_management'
9
+ require_relative 'stub_hub_api/account_management_sale'
10
+ require_relative 'stub_hub_api/event'
11
+ require_relative 'stub_hub_api/listing'
12
+ require_relative 'stub_hub_api/search'
13
+ require_relative 'stub_hub_api/alert'
14
+
15
+
16
+ module StubHubApi;end
@@ -0,0 +1,11 @@
1
+ module StubHubApi
2
+ class AccountManagement < Base
3
+ def get_listing(listing_id, options = {})
4
+ get_query_api("/accountmanagement/listings/v1/#{listing_id}", options)
5
+ end
6
+
7
+ def get_listings(user_id, options = {})
8
+ get_query_api("/accountmanagement/listings/v1/seller/#{user_id}", options)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module StubHubApi
2
+ class AccountManagementSale < Base
3
+ def get_sales(user_id, options = {})
4
+ get_query_api("/accountmanagement/sales/v1/seller/#{user_id}", options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ module StubHubApi
2
+ class Alert < Base
3
+ def create(user_id, options = {})
4
+ post_query_api("/user/customers/v1/#{user_id}/pricealerts", true, options)
5
+ end
6
+
7
+ def update(user_id, options = {})
8
+ put_query_api("/user/customers/v1/#{user_id}/pricealerts/#{alert_id}", true, options)
9
+ end
10
+
11
+ def delete(user_id, alert_id)
12
+ delete_query_api("/user/customers/v1/#{user_id}/pricealerts/#{alert_id}")
13
+ end
14
+
15
+ def show(user_id, alert_id, options = {})
16
+ get_query_api("/user/customers/v1/#{user_id}/pricealerts/#{alert_id}", false, options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,82 @@
1
+ module StubHubApi
2
+ class Base
3
+ attr_reader :token, :sandbox
4
+
5
+ def initialize(token:, sandbox:)
6
+ @token = token
7
+ @sandbox = sandbox
8
+ end
9
+
10
+ def get_query_api url, options
11
+ session.get(make_request_url(url, options)).body
12
+ end
13
+
14
+ def post_query_api url, payload = false, options
15
+ if payload
16
+ session.post do |req|
17
+ req.url url
18
+ req.headers['Content-Type'] = 'application/json'
19
+ req.body = options.to_json
20
+ end.body
21
+ else
22
+ session.post(url, builder_options(options)).body
23
+ end
24
+ end
25
+
26
+ def delete_query_api url
27
+ session.delete(make_request_url(url, {}))
28
+ end
29
+
30
+ def put_query_api url, payload = false, options
31
+ if payload
32
+ session.put do |req|
33
+ req.url url
34
+ req.headers['Content-Type'] = 'application/json'
35
+ req.body = options.to_json
36
+ end.body
37
+ else
38
+ session.put(url, builder_options(options)).body
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def sandbox_base_url
45
+ 'https://api.stubhubsandbox.com'
46
+ end
47
+
48
+ def base_url
49
+ 'https://api.stubhub.com'
50
+ end
51
+
52
+ def current_base_url
53
+ sandbox ? sandbox_base_url : base_url
54
+ end
55
+
56
+ def make_request_url url, options
57
+ "#{url}#{builder_options(options)}"
58
+ end
59
+
60
+ def builder_options options
61
+ options.any? ? "?#{to_query(options)}" : ''
62
+ end
63
+
64
+ def to_query(options)
65
+ Faraday::Utils.build_nested_query(options)
66
+ end
67
+
68
+ def session
69
+ return @connection if @connection
70
+
71
+ @connection = ::Faraday.new current_base_url, ssl: {verify: false} do |conn|
72
+ conn.use Faraday::Response::StubHub
73
+ conn.request :url_encoded
74
+ conn.response :logger
75
+ conn.adapter Faraday.default_adapter
76
+ end
77
+ @connection.authorization :Bearer, token
78
+ @connection
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,7 @@
1
+ module StubHubApi
2
+ class Event < Base
3
+ def get_event(event_id, options = {})
4
+ get_query_api("/catalog/events/v2/#{event_id}", options)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ module StubHubApi
2
+ class Listing < Base
3
+ def create(options = {})
4
+ post_query_api("/inventory/listings/v1", true, options)
5
+ end
6
+
7
+ def create_with_barcode(options = {})
8
+ post_query_api("/inventory/listings/v1/barcodes", true, options)
9
+ end
10
+
11
+ def delete(listing_id)
12
+ delete_query_api("/inventory/listings/v1/#{listing_id}")
13
+ end
14
+
15
+ def update(listing_id, options = {})
16
+ put_query_api("/inventory/listings/v1/#{listing_id}", true, options)
17
+ end
18
+
19
+ def show(listing_id, options = {})
20
+ get_query_api("/inventory/listings/v1/#{listing_id}", options)
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,41 @@
1
+ module StubHubApi
2
+ class Login < Base
3
+ attr_reader :response
4
+
5
+ def initialize(consumer_key:, consumer_secret:, username:, password:)
6
+ @consumer_key = consumer_key
7
+ @consumer_secret = consumer_secret
8
+ @username = username
9
+ @password = password
10
+ init
11
+ end
12
+
13
+ def full_response
14
+ response
15
+ end
16
+
17
+ def user_id
18
+ response.headers['x-stubhub-user-guid']
19
+ end
20
+
21
+ def account
22
+ response.body
23
+ end
24
+
25
+ private
26
+ def session
27
+ return @conn if @conn
28
+
29
+ @conn = Faraday.new(:url => base_url, :ssl => {:verify => false}) do |faraday|
30
+ faraday.request :url_encoded
31
+ faraday.adapter Faraday.default_adapter
32
+ end
33
+ @conn.basic_auth(@consumer_key, @consumer_secret)
34
+ @conn
35
+ end
36
+
37
+ def init
38
+ @response = session.post '/login', { grant_type: 'password', username: @username, password: @password, scope: 'SANDBOX' }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,28 @@
1
+ #api exception
2
+ class ApiException < StandardError;end
3
+
4
+ module Faraday
5
+ class Response::StubHub < Response::Middleware
6
+ def parse_body(body)
7
+ JSON.load(body)
8
+ end
9
+
10
+ def check_status(env)
11
+ status = env[:status].to_s
12
+ body = env[:body]
13
+ if status =~ /^5/
14
+ raise ApiException.new({status: status, body: body})
15
+ elsif status =~ /^4/
16
+ raise ApiException.new({status: status, body: body})
17
+ end
18
+ end
19
+
20
+ def call(environment)
21
+ @app.call(environment).on_complete do |env|
22
+ check_status(env)
23
+ env[:body] = parse_body(env[:body])
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ module StubHubApi
2
+ class Search < Base
3
+ def listing(options = {})
4
+ get_query_api("/search/inventory/v1", options)
5
+ end
6
+
7
+ def section(options = {})
8
+ get_query_api("/search/inventory/v1/sectionsummary", options)
9
+ end
10
+
11
+ def event(options = {})
12
+ get_query_api("/search/catalog/events/v2", options)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module StubHubApi
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'stub_hub_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "stub_hub_api"
8
+ spec.version = StubHubApi::VERSION
9
+ spec.authors = ["chebyte"]
10
+ spec.email = ["mauro@hashdog.com"]
11
+ spec.summary = %q{Gem for StubHub}
12
+ spec.description = %q{This gem provides access to add, edit and delete listings appearing on StubHub.}
13
+ spec.homepage = "http://hashdog.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_runtime_dependency 'faraday', '~> 0.9', '>= 0.9.0'
24
+ spec.add_runtime_dependency 'json', '~> 1.8.1', '>= 1.8.1'
25
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stub_hub_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - chebyte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.9'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.9.0
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '0.9'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.9.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: json
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.8.1
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.8.1
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.1
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.8.1
81
+ description: This gem provides access to add, edit and delete listings appearing on
82
+ StubHub.
83
+ email:
84
+ - mauro@hashdog.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - Gemfile
91
+ - LICENSE.txt
92
+ - README.md
93
+ - Rakefile
94
+ - lib/stub_hub_api.rb
95
+ - lib/stub_hub_api/account_management.rb
96
+ - lib/stub_hub_api/account_management_sale.rb
97
+ - lib/stub_hub_api/alert.rb
98
+ - lib/stub_hub_api/base.rb
99
+ - lib/stub_hub_api/event.rb
100
+ - lib/stub_hub_api/listing.rb
101
+ - lib/stub_hub_api/login.rb
102
+ - lib/stub_hub_api/response.rb
103
+ - lib/stub_hub_api/search.rb
104
+ - lib/stub_hub_api/version.rb
105
+ - stub_hub_api.gemspec
106
+ homepage: http://hashdog.com
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Gem for StubHub
130
+ test_files: []