bigcartel-api 0.0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8394aeb53563b44d32a5b410ff3e237c88f13364
4
+ data.tar.gz: bc61e7136220fd7512c4d8beb34c260ca0873b9c
5
+ SHA512:
6
+ metadata.gz: 730ae996d6baab3277989018c5b4b47ebd58992e89da315d6ee2d1c6fd33790e96a17c8d873219f0e3e6fb1584d46fd129b6fe4438fd84f8243bfb93071ffd20
7
+ data.tar.gz: 9f67cc67807bb236bd3a950a52a076678ecd11cd34514184b9c8be0ce38511ea8cd9fd35a4d137a595149259bdd73ac9b5a6648b1ea3738e96a4ebe0ae1a47a5
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bigcartel.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'dotenv'
8
+ end
9
+
10
+ group :test do
11
+ gem 'rspec'
12
+ gem 'webmock'
13
+ gem 'vcr'
14
+ gem 'dotenv'
15
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dylan Montgomery
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,57 @@
1
+ # Bigcartel
2
+
3
+ The bigcartel-api gem is a ruby wrapper for interacting with the Bigcartel API.
4
+ Developed for [Hipment](http://hipment.com).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'bigcartel-api'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install bigcartel-api
21
+
22
+ ## Getting Started
23
+
24
+ This gem requires a Bigcartel OAuth access token. There is a Bigcartel omniauth strategy here: [https://github.com/citizens/omniauth-bigcartel](https://github.com/citizens/omniauth-bigcartel)
25
+ ## Authentication
26
+
27
+ ```ruby
28
+ Bigcartel.api_key = 'YOUR ACCESS TOKEN'
29
+ ```
30
+
31
+ ## Account
32
+ To get information about the authenticated account:
33
+
34
+ ```ruby
35
+ Bigcartel::Account.retrieve
36
+ ```
37
+
38
+ ## Orders
39
+ To get all orders:
40
+
41
+ ```ruby
42
+ Bigcartel::Order.all
43
+ ```
44
+
45
+ To get a particular order:
46
+
47
+ ```ruby
48
+ Bigcartel::Order.find(order_number)
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/citizens/bigcartel-api/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bigcartel/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bigcartel-api"
8
+ spec.version = Bigcartel::VERSION
9
+ spec.authors = ["Dylan Montgomery"]
10
+ spec.email = ["mail@citizensinspace.com"]
11
+ spec.summary = %q{Ruby wrapper for the Bigcartel API}
12
+ spec.homepage = "https://github.com/citizens/bigcartel-api"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_dependency 'rest-client'
24
+ spec.add_dependency 'json'
25
+ spec.add_dependency 'recursive-open-struct'
26
+ spec.add_dependency 'queryparams'
27
+ end
@@ -0,0 +1,12 @@
1
+ require 'recursive-open-struct'
2
+ require "bigcartel/version"
3
+ require "bigcartel/api"
4
+ require "bigcartel/bigcartel_object"
5
+ require "bigcartel/account"
6
+ require "bigcartel/order"
7
+
8
+ module Bigcartel
9
+ class << self
10
+ attr_accessor :api_key
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Bigcartel
2
+ class Account < BigcartelObject
3
+ class << self
4
+ def retrieve
5
+ response = Bigcartel::API.get("/account")
6
+ self.new(response)
7
+ end
8
+
9
+ def root_path
10
+ '/account'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module Bigcartel
5
+ class API
6
+ class << self
7
+ def get(path)
8
+ normalize_response RestClient.get(api_url(path), authorization: "Bearer #{Bigcartel.api_key}")
9
+ end
10
+
11
+ private
12
+
13
+ def base_url
14
+ "https://api.bigcartel.com"
15
+ end
16
+
17
+ def normalize_response(response)
18
+ JSON.parse(response)
19
+ end
20
+
21
+ def api_url(path)
22
+ "#{base_url}#{path}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ module Bigcartel
2
+ class BigcartelObject < RecursiveOpenStruct
3
+ class << self
4
+ def all
5
+ resp = Bigcartel::API.get("#{root_path}")
6
+ resp['data'].map { |object| self.new(object) }
7
+ end
8
+
9
+ def find(id)
10
+ response = Bigcartel::API.get("#{root_path}/#{id}")
11
+ self.new(response)
12
+ end
13
+
14
+ def root_path
15
+ class_name = self.to_s.gsub(/^.*::/, '').downcase
16
+ "/#{class_name}s"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ module Bigcartel
2
+ class Order < BigcartelObject
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Bigcartel
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcartel::Account, vcr: true do
4
+ it_should_behave_like 'a retrievable object', Bigcartel::Account, [
5
+ :id, :subdomain, :store_name, :contact_email, :url, :website
6
+ ]
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bigcartel::Order, vcr: true do
4
+ attributes = [
5
+ :number, :buyer_first_name, :buyer_first_name, :shipping_address_1, :shipping_address_1,
6
+ :shipping_address_2, :shipping_city, :shipping_state, :shipping_zip, :shipping_status,
7
+ :shipping_latitude, :shipping_longitude, :completed_at, :shipping_country, :items
8
+ ]
9
+
10
+ it_should_behave_like 'a findable object', ENV['BIGCARTEL_ORDER_ID'], attributes
11
+ it_should_behave_like 'a listable object', Bigcartel::Order, attributes
12
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.shared_examples 'a findable object' do |id, attributes|
2
+ let(:object) { VCR.use_cassette("#{subject.class.to_s}_#{id}") { subject.class.find(id) } }
3
+
4
+ attributes.each do |attribute|
5
+ it "should return a value for #{attribute}" do
6
+ expect(object.respond_to?(attribute)).to be true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ RSpec.shared_examples 'a listable object' do |subject, attributes = []|
2
+ let(:list) { VCR.use_cassette(subject.to_s) { subject.all } }
3
+
4
+ it "should return an array of objects" do
5
+ expect(list.class).to eq Array
6
+ expect(list.first.class).to eq subject
7
+ end
8
+
9
+ attributes.each do |attribute|
10
+ it "should return a value for #{attribute}" do
11
+ expect(list.first.respond_to?(attribute)).to be true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ RSpec.shared_examples 'a retrievable object' do |subject, attributes|
2
+ let(:object) { VCR.use_cassette(subject.to_s) { subject.retrieve } }
3
+
4
+ attributes.each do |attribute|
5
+ it "should return a value for #{attribute}" do
6
+ expect(object.respond_to?(attribute)).to be true
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,110 @@
1
+ require 'bigcartel'
2
+ require 'vcr'
3
+ require 'dotenv'
4
+
5
+ Dotenv.load
6
+ Bigcartel.api_key = ENV['BIGCARTEL_TOKEN']
7
+
8
+ # Load shared examples
9
+ Dir['./spec/shared_examples/**/*.rb'].sort.each { |f| require f }
10
+
11
+ # This file was generated by the `rspec --init` command. Conventionally, all
12
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
13
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
14
+ # this file to always be loaded, without a need to explicitly require it in any
15
+ # files.
16
+ #
17
+ # Given that it is always loaded, you are encouraged to keep this file as
18
+ # light-weight as possible. Requiring heavyweight dependencies from this file
19
+ # will add to the boot time of your test suite on EVERY test run, even for an
20
+ # individual file that may not need all of that loaded. Instead, consider making
21
+ # a separate helper file that requires the additional dependencies and performs
22
+ # the additional setup, and require it from the spec files that actually need
23
+ # it.
24
+ #
25
+ # The `.rspec` file also contains a few flags that are not defaults but that
26
+ # users commonly want.
27
+ #
28
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
29
+
30
+ VCR.configure do |c|
31
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
32
+ c.hook_into :webmock
33
+ c.ignore_localhost = false
34
+ c.configure_rspec_metadata!
35
+ c.default_cassette_options = { record: :once }
36
+ end
37
+
38
+ RSpec.configure do |config|
39
+ # rspec-expectations config goes here. You can use an alternate
40
+ # assertion/expectation library such as wrong or the stdlib/minitest
41
+ # assertions if you prefer.
42
+ config.expect_with :rspec do |expectations|
43
+ # This option will default to `true` in RSpec 4. It makes the `description`
44
+ # and `failure_message` of custom matchers include text for helper methods
45
+ # defined using `chain`, e.g.:
46
+ # be_bigger_than(2).and_smaller_than(4).description
47
+ # # => "be bigger than 2 and smaller than 4"
48
+ # ...rather than:
49
+ # # => "be bigger than 2"
50
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
51
+ end
52
+
53
+ # rspec-mocks config goes here. You can use an alternate test double
54
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
55
+ config.mock_with :rspec do |mocks|
56
+ # Prevents you from mocking or stubbing a method that does not exist on
57
+ # a real object. This is generally recommended, and will default to
58
+ # `true` in RSpec 4.
59
+ mocks.verify_partial_doubles = true
60
+ end
61
+
62
+ # The settings below are suggested to provide a good initial experience
63
+ # with RSpec, but feel free to customize to your heart's content.
64
+ =begin
65
+ # These two settings work together to allow you to limit a spec run
66
+ # to individual examples or groups you care about by tagging them with
67
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
68
+ # get run.
69
+ config.filter_run :focus
70
+ config.run_all_when_everything_filtered = true
71
+
72
+ # Limits the available syntax to the non-monkey patched syntax that is
73
+ # recommended. For more details, see:
74
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
75
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
76
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
77
+ config.disable_monkey_patching!
78
+
79
+ # This setting enables warnings. It's recommended, but in some cases may
80
+ # be too noisy due to issues in dependencies.
81
+ config.warnings = true
82
+
83
+ # Many RSpec users commonly either run the entire suite or an individual
84
+ # file, and it's useful to allow more verbose output when running an
85
+ # individual spec file.
86
+ if config.files_to_run.one?
87
+ # Use the documentation formatter for detailed output,
88
+ # unless a formatter has already been configured
89
+ # (e.g. via a command-line flag).
90
+ config.default_formatter = 'doc'
91
+ end
92
+
93
+ # Print the 10 slowest examples and example groups at the
94
+ # end of the spec run, to help surface which specs are running
95
+ # particularly slow.
96
+ config.profile_examples = 10
97
+
98
+ # Run specs in random order to surface order dependencies. If you find an
99
+ # order dependency and want to debug it, you can fix the order by providing
100
+ # the seed, which is printed after each run.
101
+ # --seed 1234
102
+ config.order = :random
103
+
104
+ # Seed global randomization in this process using the `--seed` CLI option.
105
+ # Setting this allows you to use `--seed` to deterministically reproduce
106
+ # test failures related to randomization by passing the same `--seed` value
107
+ # as the one that triggered the failure.
108
+ Kernel.srand config.seed
109
+ =end
110
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bigcartel-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Dylan Montgomery
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-20 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: recursive-open-struct
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: queryparams
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - mail@citizensinspace.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - Gemfile
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - bigcartel.gemspec
109
+ - lib/bigcartel.rb
110
+ - lib/bigcartel/account.rb
111
+ - lib/bigcartel/api.rb
112
+ - lib/bigcartel/bigcartel_object.rb
113
+ - lib/bigcartel/order.rb
114
+ - lib/bigcartel/version.rb
115
+ - spec/account_spec.rb
116
+ - spec/order_spec.rb
117
+ - spec/shared_examples/findable.rb
118
+ - spec/shared_examples/listable.rb
119
+ - spec/shared_examples/retrievable.rb
120
+ - spec/spec_helper.rb
121
+ homepage: https://github.com/citizens/bigcartel-api
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.4.7
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Ruby wrapper for the Bigcartel API
145
+ test_files:
146
+ - spec/account_spec.rb
147
+ - spec/order_spec.rb
148
+ - spec/shared_examples/findable.rb
149
+ - spec/shared_examples/listable.rb
150
+ - spec/shared_examples/retrievable.rb
151
+ - spec/spec_helper.rb