foxycart 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ .ruby-version
3
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,6 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Dana Woodman, Teleporter.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,67 @@
1
+ # FoxyCart Ruby Library
2
+
3
+ **THIS IS A WORK IN PROGRESS, COME BACK SOON!**
4
+
5
+ A Ruby wrapper for the new FoxyCart Hypermedia REST API.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ gem install foxycart
11
+ ```
12
+
13
+ ...or...
14
+
15
+ ```ruby
16
+ gem 'foxycart'
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ Below is an example of how to create a store using the FoxyCart gem:
22
+
23
+ ```ruby
24
+ require 'foxycart'
25
+
26
+ FoxyCart.api_key = '<YOUR-KEY-HERE>'
27
+ FoxyCart::Store.create(
28
+ :store_name => 'My Test Store',
29
+ :store_domain => 'some-subdomain',
30
+ :store_url => 'http://example.com',
31
+ :store_email => 'test@example.com',
32
+ :postal_code => '98765',
33
+ :country => 'US',
34
+ :region => 'CA',
35
+ )
36
+ ```
37
+
38
+ Check out the list of available interfaces below.
39
+
40
+ ## Reference
41
+
42
+ **This is a work in progress, many features are still missing. The FoxyCart API itself is not finalized so this may change at any time!**
43
+
44
+ ### FoxyCart::Store
45
+
46
+ [FoxyCart Store API Reference](http://api.foxycart.com/rels/store)
47
+
48
+ Supported Methods:
49
+
50
+ - `create`
51
+
52
+
53
+ ## Development
54
+
55
+ 1. Fork
56
+ 2. Make changes (and add tests/docs!)
57
+ 3. Submit pull request
58
+ 4. ???
59
+ 5. Profit!
60
+
61
+ ## License
62
+
63
+ Released under the MIT license. See the `LICENSE` file for more details.
64
+
65
+ ## Credit
66
+
67
+ Written by [Dana Woodman](http://danawoodman.com) and of [Teleporter.io](http://teleporter.io), based heavily on the [Stripe Ruby gem](https://github.com/stripe/stripe-ruby).
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ require 'foxycart/version'
5
+ require 'date'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.required_ruby_version = '>= 1.9.3'
9
+ s.authors = ['danawoodman', 'teleporter']
10
+ s.date = Date.today.strftime('%Y-%m-%d')
11
+ s.description = <<-HERE
12
+ A Ruby interface FoxyCart Hypermedia RESTful API.
13
+ HERE
14
+ s.email = 'hire@teleporter.io'
15
+ s.extra_rdoc_files = %w[README.md LICENSE]
16
+ s.homepage = 'http://github.com/teleporter/foxycart'
17
+ s.license = 'MIT'
18
+ s.name = 'foxycart'
19
+ s.rdoc_options = ['--charset=UTF-8']
20
+ s.require_paths = ['lib']
21
+ s.summary = "Ruby interface to FoxyCart's Hypermedia RESTful API."
22
+ s.version = FoxyCart::VERSION
23
+
24
+ s.add_dependency 'bundler', '~> 1.3'
25
+ s.add_dependency 'rest-client', '~> 1.6'
26
+
27
+ s.add_development_dependency 'rspec', '~> 2.14'
28
+ s.add_development_dependency 'guard', '~> 2.2'
29
+ s.add_development_dependency 'guard-rspec', '~> 4.0'
30
+
31
+ s.files = `git ls-files`.split("\n")
32
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
33
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |file| File.basename(file) }
34
+ end
@@ -0,0 +1,78 @@
1
+ require 'rest_client'
2
+
3
+ # Version
4
+ require 'foxycart/version'
5
+
6
+ # API operations
7
+ require 'foxycart/api_operations/create'
8
+ # require 'foxycart/api_operations/update'
9
+ # require 'foxycart/api_operations/delete'
10
+ # require 'foxycart/api_operations/list'
11
+
12
+ # Resources
13
+ require 'foxycart/store'
14
+
15
+ # Errors
16
+ require 'foxycart/errors/foxycart_error'
17
+ require 'foxycart/errors/authentication_error'
18
+
19
+ module FoxyCart
20
+ @api_base = 'https://api-sandbox.foxycart.com'
21
+
22
+ class << self
23
+ attr_accessor :api_key
24
+ end
25
+
26
+ def self.api_url(url='')
27
+ @api_base + url
28
+ end
29
+
30
+ def self.request_headers(api_key)
31
+ {
32
+ 'FOXYCART-API-VERSION' => '1',
33
+ 'Authorization' => "Bearer #{api_key}",
34
+ }
35
+ end
36
+
37
+ def self.request(method, url, api_key, params={}, headers={})
38
+ unless api_key ||= @api_key
39
+ raise AuthenticationError.new('No API key provided. ' +
40
+ 'Set your API key using "FoxyCart.api_key = <API-KEY>".')
41
+ end
42
+
43
+ url = api_url(url)
44
+
45
+ case method.to_s.downcase.to_sym
46
+ when :get, :head, :delete
47
+ # Make params into GET parameters
48
+ url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
49
+ payload = nil
50
+ else
51
+ payload = uri_encode(params)
52
+ end
53
+
54
+ # post(url, data: post_data, headers: FoxyCart.headers)
55
+ request_opts = {
56
+ :headers => request_headers(api_key).update(headers),
57
+ :method => method,
58
+ :open_timeout => 30,
59
+ :payload => payload,
60
+ :url => url,
61
+ :timeout => 80
62
+ }
63
+
64
+ execute_request(request_opts)
65
+ end
66
+
67
+ private
68
+
69
+ def self.uri_encode(params)
70
+ Util.flatten_params(params).
71
+ map { |k,v| "#{k}=#{Util.url_encode(v)}" }.join('&')
72
+ end
73
+
74
+ def self.execute_request(opts)
75
+ RestClient::Request.execute(opts)
76
+ end
77
+
78
+ end
@@ -0,0 +1,16 @@
1
+ module FoxyCart
2
+ module APIOperations
3
+ module Create
4
+ module ClassMethods
5
+ def create(params={})
6
+ response = FoxyCart.request(:post, self.url, params)
7
+ Util.convert_to_stripe_object(response, api_key)
8
+ end
9
+ end
10
+
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ end
14
+ end
15
+ end
16
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module FoxyCart
2
+ class AuthenticationError < FoxyCartError; end
3
+ end
@@ -0,0 +1,13 @@
1
+ module FoxyCart
2
+ class FoxyCartError < StandardError
3
+ attr_reader :message
4
+
5
+ def initialize(message=nil)
6
+ @message = message
7
+ end
8
+
9
+ def to_s
10
+ "#{@message}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module FoxyCart
2
+ class Store
3
+ include FoxyCart::APIOperations::Create
4
+
5
+ @store_version = 'https://admin.foxycart.com/v/0.7.2/'
6
+ @country = 'US'
7
+
8
+ def url
9
+ "/users/#{@user_id}/stores"
10
+ end
11
+
12
+ # def create(params={})
13
+ # @user_id = params['user_id']
14
+ # @name = params['name']
15
+ # @domain = @name.parameterize
16
+ # @url = params['url']
17
+ # @email = params['email']
18
+ # @zip = params['zip']
19
+ # @state = params['state']
20
+ # end
21
+ # {
22
+ # :store_version_uri => @store_version,
23
+ # :store_name => @name,
24
+ # :store_domain => @domain,
25
+ # :store_url => @url,
26
+ # :store_email => @email,
27
+ # :postal_code => @zip,
28
+ # :country => @country,
29
+ # :region => @state,
30
+ # }
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module FoxyCart
2
+ class Util
3
+ def self.url_encode(key)
4
+ URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
5
+ end
6
+
7
+ def self.flatten_params(params, parent_key=nil)
8
+ result = []
9
+ params.each do |key, value|
10
+ calculated_key = parent_key ? "#{parent_key}[#{url_encode(key)}]" : url_encode(key)
11
+ if value.is_a?(Hash)
12
+ result += flatten_params(value, calculated_key)
13
+ elsif value.is_a?(Array)
14
+ result += flatten_params_array(value, calculated_key)
15
+ else
16
+ result << [calculated_key, value]
17
+ end
18
+ end
19
+ result
20
+ end
21
+
22
+ def self.flatten_params_array(value, calculated_key)
23
+ result = []
24
+ value.each do |elem|
25
+ if elem.is_a?(Hash)
26
+ result += flatten_params(elem, calculated_key)
27
+ elsif elem.is_a?(Array)
28
+ result += flatten_params_array(elem, calculated_key)
29
+ else
30
+ result << ["#{calculated_key}[]", elem]
31
+ end
32
+ end
33
+ result
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module FoxyCart
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+ require 'foxycart'
3
+
4
+ describe "Store" do
5
+ before :each do
6
+ FoxyCart.api_key = 'asdf'
7
+ end
8
+
9
+ it "does stuff" do
10
+ puts FoxyCart.api_key
11
+ # FoxyCart::Store.create(
12
+ # :store_name => 'My Test Store',
13
+ # :store_domain => 'some-subdomain',
14
+ # :store_url => 'http://example.com',
15
+ # :store_email => 'test@example.com',
16
+ # :postal_code => '98765',
17
+ # :country => 'US',
18
+ # :region => 'CA',
19
+ # )
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+ config.order = 'random'
6
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foxycart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - danawoodman
9
+ - teleporter
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-11-08 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.3'
31
+ - !ruby/object:Gem::Dependency
32
+ name: rest-client
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '1.6'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.6'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.14'
63
+ - !ruby/object:Gem::Dependency
64
+ name: guard
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: '2.2'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: '2.2'
79
+ - !ruby/object:Gem::Dependency
80
+ name: guard-rspec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '4.0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '4.0'
95
+ description: ! 'A Ruby interface FoxyCart Hypermedia RESTful API.
96
+
97
+ '
98
+ email: hire@teleporter.io
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - README.md
103
+ - LICENSE
104
+ files:
105
+ - .gitignore
106
+ - Gemfile
107
+ - Guardfile
108
+ - LICENSE
109
+ - README.md
110
+ - foxycart.gemspec
111
+ - lib/foxycart.rb
112
+ - lib/foxycart/api_operations/create.rb
113
+ - lib/foxycart/api_operations/delete.rb
114
+ - lib/foxycart/api_operations/list.rb
115
+ - lib/foxycart/api_operations/update.rb
116
+ - lib/foxycart/errors/authentication_error.rb
117
+ - lib/foxycart/errors/foxycart_error.rb
118
+ - lib/foxycart/store.rb
119
+ - lib/foxycart/util.rb
120
+ - lib/foxycart/version.rb
121
+ - spec/foxycart/store_spec.rb
122
+ - spec/spec_helper.rb
123
+ homepage: http://github.com/teleporter/foxycart
124
+ licenses:
125
+ - MIT
126
+ post_install_message:
127
+ rdoc_options:
128
+ - --charset=UTF-8
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: 1.9.3
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 1.8.23
146
+ signing_key:
147
+ specification_version: 3
148
+ summary: Ruby interface to FoxyCart's Hypermedia RESTful API.
149
+ test_files:
150
+ - spec/foxycart/store_spec.rb
151
+ - spec/spec_helper.rb