ecwid_api 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f75df6f53fd6f55913cf94526d41c5cf68272ebc
4
+ data.tar.gz: e1a2a10f1141300974719d4998c962c617ce44c3
5
+ SHA512:
6
+ metadata.gz: 43e85267b0ff0a21482048c8436dc460e3045305acf73d876e0e329f8c7e90b3b62e0f76b341574735fa27e914d04ad7df7950dc44446ecd857955b54b0e6093
7
+ data.tar.gz: 044b281f10380c226f1e987b771297d56fa5ee6f213ccd5f4ed771cf628d37646e9c1abae4872096f29cc384b02eb3ab4298e0bd090b4eca4ecbaff122ceb06a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ecwid_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 David Biehl
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.
data/README.md ADDED
@@ -0,0 +1,90 @@
1
+ # EcwidApi
2
+
3
+ A gem to interface with the Ecwid REST APIs.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ecwid_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ecwid_api
18
+
19
+ ## Usage
20
+
21
+ ### Configure an new Client
22
+
23
+ A `Client` will interface with a single Ecwid store. The `store_id` will need
24
+ to be configured for each new `Client`.
25
+
26
+ require 'ecwid_api'
27
+
28
+ client = EcwidApi::Client.new do |config|
29
+ config.store_id = '12345' # your Ecwid Store ID
30
+ config.url = 'https://app.ecwid.com/api/v1' # default
31
+ config.order_secret_key = 'ORDER_SECRET_KEY'
32
+ config.product_secret_key = 'PRODUCT_SECRET_KEY'
33
+ end
34
+
35
+ ### Make some Requests
36
+
37
+ To make a request, simply call the `#get` method on the client passing in the
38
+ API and any parameters it requires. For example, to get some categories:
39
+
40
+ # GET https://app.ecwid.com/api/v1/[STORE-ID]/categories?parent=1
41
+
42
+ client.get("categories", parent: 1)
43
+
44
+ # => #<Faraday::Response>
45
+
46
+ The `Client` is responsible for making raw requests, which is why it returns
47
+ a `Faraday::Response`. Eventually there will be a domain model to bury this
48
+ detail under an abstraction. In the meantime, please see the
49
+ [Faraday documentation](https://github.com/lostisland/faraday)
50
+ to learn how to use the `Faraday::Response` object.
51
+
52
+ ### Ecwid API Documentation
53
+
54
+ The [Ecwid API documentation](http://kb.ecwid.com/w/page/25232810/API)
55
+ should give you a good idea of what is possible to retreive. Please note that
56
+ resources requiring the secret keys will be inaccessible until we implement
57
+ that feature.
58
+
59
+ ## Contributing
60
+
61
+ 1. Fork it ( http://github.com/davidbiehl/ecwid_api/fork )
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. Create new Pull Request
66
+
67
+ ## License
68
+
69
+ The MIT License (MIT)
70
+
71
+ Copyright (c) 2014 David Biehl
72
+
73
+ Permission is hereby granted, free of charge, to any person obtaining a copy
74
+ of this software and associated documentation files (the "Software"), to deal
75
+ in the Software without restriction, including without limitation the rights
76
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
77
+ copies of the Software, and to permit persons to whom the Software is
78
+ furnished to do so, subject to the following conditions:
79
+
80
+ The above copyright notice and this permission notice shall be included in
81
+ all copies or substantial portions of the Software.
82
+
83
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
84
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
85
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
86
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
87
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
88
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
89
+ THE SOFTWARE.
90
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/ecwid_api.gemspec ADDED
@@ -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 'ecwid_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ecwid_api"
8
+ spec.version = EcwidApi::VERSION
9
+ spec.authors = ["David Biehl"]
10
+ spec.email = ["me@davidbiehl.com"]
11
+ spec.summary = %q{A client for the Ecwid REST API}
12
+ spec.homepage = ""
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.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec", "~> 2.14.1"
23
+
24
+ spec.add_dependency "faraday", "~> 0.9.0"
25
+ end
@@ -0,0 +1,86 @@
1
+ require 'faraday'
2
+
3
+ module EcwidApi
4
+ # Public: Client objects manage the connection and interface to a single Ecwid
5
+ # store.
6
+ #
7
+ # Examples
8
+ #
9
+ # client = EcwidApi::Client.new do |config|
10
+ # config.store_id = '12345'
11
+ # config.url = 'http://app.ecwid.com/api/v1'
12
+ # config.order_secret_key = 'ORDER_SECRET_KEY'
13
+ # config.product_secret_key = 'PRODUCT_SECRET_KEY'
14
+ # end
15
+ #
16
+ class Client
17
+ # The default base URL for the Ecwid API
18
+ DEFAULT_URL = "https://app.ecwid.com/api/v1"
19
+
20
+ # Public: Returns the Ecwid Store ID
21
+ attr_reader :store_id
22
+
23
+ # Public: Gets or sets the Order API Secret Key for the Ecwid Store
24
+ attr_accessor :order_secret_key
25
+
26
+ # Public: Gets or sets the default Product API Secret Key for the Ecwid Store
27
+ attr_accessor :product_secret_key
28
+
29
+ def initialize
30
+ yield(self) if block_given?
31
+ raise Error.new("The store_id is required") unless store_id
32
+ end
33
+
34
+ # Public: Returns the base URL of the Ecwid API
35
+ def url
36
+ @url || DEFAULT_URL
37
+ end
38
+
39
+ # Public: Sets the base URL for the Ecwid API
40
+ def url=(url)
41
+ reset_connection
42
+ @url = url
43
+ end
44
+
45
+ # Public: Sets the Ecwid Store ID
46
+ def store_id=(store_id)
47
+ reset_connection
48
+ @store_id = store_id
49
+ end
50
+
51
+ # Public: The URL of the API for the Ecwid Store
52
+ def store_url
53
+ "#{url}/#{store_id}"
54
+ end
55
+
56
+ # Public: Sends a GET request to the Ecwid API
57
+ #
58
+ # path - The String path for the URL of the request without the base URL
59
+ # params - A Hash of query string parameters
60
+ #
61
+ # Examples
62
+ #
63
+ # # Gets the Categories where the parent Category is 1
64
+ # client.get("categories", parent: 1)
65
+ # # => #<Faraday::Response>
66
+ #
67
+ # Returns a Faraday::Response
68
+ def get(path, params={})
69
+ connection.get(path, params)
70
+ end
71
+
72
+ private
73
+
74
+ # Private: Resets the connection.
75
+ #
76
+ # Should be used if the base URL to the Ecwid API changes
77
+ def reset_connection
78
+ @connection = nil
79
+ end
80
+
81
+ # Private: Returns a Faraday connection to interface with the Ecwid API
82
+ def connection
83
+ @connection ||= Faraday.new(url: store_url)
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module EcwidApi
2
+ class Error < StandardError; end;
3
+ end
@@ -0,0 +1,3 @@
1
+ module EcwidApi
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ecwid_api.rb ADDED
@@ -0,0 +1,34 @@
1
+ require "ecwid_api/version"
2
+
3
+ # Public: This is the main namespace for the EcwidApi. It can be used to store
4
+ # the default client.
5
+ #
6
+ module EcwidApi
7
+ autoload :Client, "ecwid_api/client"
8
+ autoload :Error, "ecwid_api/error"
9
+
10
+ class << self
11
+ # Public: Gets and configures a default client
12
+ #
13
+ # To configure the default client, just pass a block.
14
+ #
15
+ # Examples
16
+ #
17
+ # EcwidApi.default_client do |config|
18
+ # config.store_id = '12345'
19
+ # config.order_secret_key = 'ORDER_SECRET_KEY'
20
+ # config.product_secret_key = 'PRODUCT_SECRET_KEY'
21
+ # end
22
+ #
23
+ # client = EcwidApi.default_client.store_id
24
+ # # => "12345"
25
+ #
26
+ # Returns an EcwidApi::Client, or null if one hasn't been configured
27
+ def default_client(&block)
28
+ if block_given?
29
+ @default_client = Client.new(&block)
30
+ end
31
+ @default_client
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ require "spec_helper"
2
+
3
+ describe EcwidApi::Client do
4
+ subject do
5
+ EcwidApi::Client.new do |config|
6
+ config.store_id = store_id
7
+ end
8
+ end
9
+ let(:store_id) { 12345 }
10
+
11
+ context "without a store_id" do
12
+ it "raises an error" do
13
+ expect { EcwidApi::Client.new }.to raise_error(EcwidApi::Error, /store_id/)
14
+ end
15
+ end
16
+
17
+ describe "#url" do
18
+ its(:url) { "http://app.ecwid.com/api/v1" }
19
+
20
+ it "can be overridden" do
21
+ client = EcwidApi::Client.new do |config|
22
+ config.store_id = store_id
23
+ config.url = "http://ladida.com"
24
+ end
25
+
26
+ client.url.should == "http://ladida.com"
27
+ end
28
+ end
29
+
30
+ describe "#store_url" do
31
+ its(:store_url) { "http://app.ecwid.com/api/v1/12345" }
32
+ end
33
+
34
+ describe "#get" do
35
+ let(:faraday_stubs) do
36
+ Faraday::Adapter::Test::Stubs.new do |stub|
37
+ stub.get('categories') { [200, {}, '[]'] }
38
+ end
39
+ end
40
+
41
+ let(:faraday) do
42
+ Faraday::new do |builder|
43
+ builder.adapter :test, faraday_stubs
44
+ end
45
+ end
46
+
47
+ before(:each) do
48
+ allow(subject).to receive(:connection).and_return(faraday)
49
+ end
50
+
51
+ it "delegates to the Faraday connection" do
52
+ expect(subject.send(:connection)).to receive(:get).with("categories", parent: 1)
53
+
54
+ subject.get "categories", parent: 1
55
+ end
56
+
57
+ it "returns a Faraday::Response" do
58
+ subject.get("categories", parent: 1).is_a?(Faraday::Response).should be_true
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe EcwidApi do
4
+ describe "::default_client" do
5
+ it "builds an EcwidApi::Client with the block" do
6
+ EcwidApi.default_client.should be_nil
7
+
8
+ client = EcwidApi.default_client do |config|
9
+ config.store_id = 123
10
+ end
11
+
12
+ client.is_a?(EcwidApi::Client).should be_true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ require "ecwid_api"
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ecwid_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Biehl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-06 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.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.9.0
69
+ description:
70
+ email:
71
+ - me@davidbiehl.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - ecwid_api.gemspec
83
+ - lib/ecwid_api.rb
84
+ - lib/ecwid_api/client.rb
85
+ - lib/ecwid_api/error.rb
86
+ - lib/ecwid_api/version.rb
87
+ - spec/client_spec.rb
88
+ - spec/ecwid_api_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A client for the Ecwid REST API
114
+ test_files:
115
+ - spec/client_spec.rb
116
+ - spec/ecwid_api_spec.rb
117
+ - spec/spec_helper.rb