kounta_rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a86362b8399c86197ffcd71ede44e6a9ed012680
4
+ data.tar.gz: 33815307b4c2fca7f892c79344afeb4749ae996f
5
+ SHA512:
6
+ metadata.gz: e0c96a9de798ae9e9260619d48317bc5a6ddfdc2c7f583e84ffb9f342c3e0e64412d543bb3be04fbbc71a93df60ec9af4c016591cf0ac617e4b194a4ebab5b33
7
+ data.tar.gz: 006705116209f1457a137720359cc156e7d6c287a9815ec54f9333674cd5516e56f7348d9459575d3f5157ae4fb54e08a1f4c7d1aadfdf10e41a83198b73e259
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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
+ .rspec
19
+ tokens.yml
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "spec/fixtures"]
2
+ path = spec/fixtures
3
+ url = git@github.com:Rodeoclash/Kounta-Fixtures.git
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Kounta.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Samuel Richardson
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,29 @@
1
+ # Kounta
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'kounta'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install kounta
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/console.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "./lib/kounta"
2
+ require 'pry'
3
+
4
+ tokens = YAML::load( File.open( './tokens.yml' ) )
5
+
6
+ Kounta.configure do |config|
7
+ config.client_id = tokens['client_id']
8
+ config.client_secret = tokens['client_secret']
9
+ config.client_token = tokens['client_token']
10
+ config.client_refresh_token = tokens['client_refresh_token']
11
+ config.enable_logging = true
12
+ end
13
+
14
+ binding.pry
data/kounta.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'kounta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "kounta_rest"
8
+ spec.version = Kounta::VERSION
9
+ spec.authors = ["Samuel Richardson"]
10
+ spec.email = ["sam@richardson.co.nz"]
11
+ spec.description = %q{Library for accessing Kountas RESTful API}
12
+ spec.summary = %q{Will write this}
13
+ spec.homepage = "http://www.richardson.co.nz"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ spec.add_development_dependency "simplecov", "0.7.1"
25
+ spec.add_development_dependency "webmock", "1.13.0"
26
+
27
+ spec.add_dependency "oj", "~> 2.1.4"
28
+ spec.add_dependency "hashie", "~> 2.0.5"
29
+ spec.add_dependency "oauth2", "0.9.2"
30
+ spec.add_dependency "pry", "0.9.12.2"
31
+ spec.add_dependency "yell", "1.5.1"
32
+ end
data/lib/kounta.rb ADDED
@@ -0,0 +1,76 @@
1
+ require_relative "kounta/version"
2
+ require_relative "kounta/errors"
3
+ require_relative "kounta/rest/client"
4
+ require_relative "kounta/resource"
5
+ require_relative "kounta/category"
6
+ require_relative "kounta/tax"
7
+ require_relative "kounta/product"
8
+ require_relative "kounta/address"
9
+ require_relative "kounta/payment"
10
+ require_relative "kounta/line"
11
+ require_relative "kounta/order"
12
+ require_relative "kounta/customer"
13
+ require_relative "kounta/price_list"
14
+ require_relative "kounta/site"
15
+ require_relative "kounta/company"
16
+
17
+ module Kounta
18
+
19
+ AUTHORIZATION_URI = "https://my.kounta.com/authorize"
20
+ TOKEN_URI = "https://api.kounta.com/v1/token.json"
21
+ SITE_URI = "https://api.kounta.com/v1/"
22
+ FORMAT = :json
23
+
24
+ def self.log(message)
25
+
26
+ end
27
+
28
+ def self.root
29
+ File.expand_path '../..', __FILE__
30
+ end
31
+
32
+ def self.configure
33
+ yield self
34
+ end
35
+
36
+ def self.client_id= (value)
37
+ @client_id = value
38
+ end
39
+
40
+ def self.client_id
41
+ @client_id
42
+ end
43
+
44
+ def self.client_secret= (value)
45
+ @client_secret = value
46
+ end
47
+
48
+ def self.client_secret
49
+ @client_secret
50
+ end
51
+
52
+ def self.client_token= (value)
53
+ @client_token = value
54
+ end
55
+
56
+ def self.client_token
57
+ @client_token
58
+ end
59
+
60
+ def self.client_refresh_token= (value)
61
+ @client_refresh_token = value
62
+ end
63
+
64
+ def self.client_refresh_token
65
+ @client_refresh_token
66
+ end
67
+
68
+ def self.enable_logging= (value)
69
+ @enable_logging = value
70
+ end
71
+
72
+ def self.enable_logging
73
+ @enable_logging || false
74
+ end
75
+
76
+ end
@@ -0,0 +1,18 @@
1
+ module Kounta
2
+
3
+ class Address < Kounta::Resource
4
+ property :company_id
5
+ property :people_id
6
+ property :lines
7
+ property :city
8
+ property :zone
9
+ property :postal_code
10
+ property :country
11
+
12
+ def resource_path
13
+ {people: people_id, addresses: id}
14
+ end
15
+
16
+ end
17
+
18
+ end
@@ -0,0 +1,16 @@
1
+ module Kounta
2
+
3
+ class Category < Kounta::Resource
4
+ property :company_id
5
+ property :name
6
+ property :description
7
+ property :image
8
+ property :products
9
+
10
+ def resource_path
11
+ {companies: company_id, categories: id}
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,51 @@
1
+ module Kounta
2
+
3
+ class Company < Kounta::Resource
4
+
5
+ property :name
6
+ property :shipping_address
7
+ property :postal_address
8
+ property :addresses
9
+ property :business_number
10
+ property :contact_staff_member
11
+ property :image
12
+ property :website
13
+ property :currency
14
+ property :timezone
15
+ property :sites
16
+ property :registers
17
+ property :email
18
+
19
+ has_one :product, Kounta::Product, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, products: item_id} }
20
+ has_one :category, Kounta::Category, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, categories: item_id} }
21
+ has_one :customer, Kounta::Customer, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, customers: item_id} }
22
+ has_one :site, Kounta::Site, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, sites: item_id} }
23
+ has_one :price_list, Kounta::PriceList, {:company_id => :id}, lambda { |klass, item_id| {companies: klass.id, price_lists: item_id} }
24
+
25
+ has_many :products, Kounta::Product, {:company_id => :id}, lambda { |klass| {companies: klass.id, products: nil} }
26
+ has_many :categories, Kounta::Category, {:company_id => :id}, lambda { |klass| {companies: klass.id, categories: nil} }
27
+ has_many :customers, Kounta::Customer, {:company_id => :id}, lambda { |klass| {companies: klass.id, customers: nil} }
28
+ has_many :sites, Kounta::Site, {:company_id => :id}, lambda { |klass| {companies: klass.id, sites: nil} }
29
+ has_many :price_lists, Kounta::PriceList, {:company_id => :id}, lambda { |klass| {companies: klass.id, price_lists: nil} }
30
+ has_many :taxes, Kounta::Tax, {:company_id => :id}, lambda { |klass| {companies: klass.id, taxes: nil} }
31
+
32
+ def initialize(hash={})
33
+ if hash.empty?
34
+ response = client.perform({:companies => "me"}, :get)
35
+ super(response)
36
+ else
37
+ super(hash)
38
+ end
39
+ end
40
+
41
+ def base_price_list
42
+ client.object_from_response(Kounta::PriceList, :get, {companies: id, price_lists: 'base'})
43
+ end
44
+
45
+ def resource_path
46
+ {companies: id}
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,35 @@
1
+ module Kounta
2
+
3
+ class Customer < Kounta::Resource
4
+ property :company_id
5
+ property :people_id
6
+ property :first_name
7
+ property :last_name
8
+ property :primary_email_address
9
+ property :description
10
+ property :email_addresses
11
+ property :phone
12
+ property :mobile
13
+ property :fax
14
+ property :shipping_address
15
+ property :postal_address
16
+ property :addresses
17
+ property :image
18
+ property :tags
19
+
20
+ has_one :address, Kounta::Address, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, addresses: item_id} }
21
+ has_one :order, Kounta::Order, {:company_id => :company_id}, lambda { |klass, item_id| {companies: klass.company_id, orders: item_id} }
22
+ has_many :addresses, Kounta::Address, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, addresses: nil} }
23
+ has_many :orders, Kounta::Order, {:company_id => :company_id}, lambda { |klass| {companies: klass.company_id, orders: nil} }
24
+
25
+ def name
26
+ "#{first_name} #{last_name}"
27
+ end
28
+
29
+ def resource_path
30
+ {companies: company_id, customers: id}
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,7 @@
1
+ module Kounta
2
+ module Errors
3
+ class KountaError < StandardError; end
4
+ class MissingOauthDetails < KountaError; end
5
+ class UnknownResourceAttribute < KountaError; end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ module Kounta
2
+
3
+ class Line < Kounta::Resource
4
+ property :company_id
5
+ property :order_id
6
+ property :product_id
7
+ property :number
8
+ property :quantity
9
+ property :notes
10
+ property :price_variation
11
+ property :product
12
+ property :unit_price
13
+ property :unit_tax
14
+
15
+ coerce_key :product, Kounta::Product
16
+
17
+ def resource_path
18
+ {companies: company_id, orders: order_id, lines: id}
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,47 @@
1
+ module Kounta
2
+
3
+ class Order < Kounta::Resource
4
+ property :company_id
5
+ property :status
6
+ property :customer
7
+ property :register_id
8
+ property :site_id
9
+ property :lines
10
+ property :payments
11
+ property :callback_uri
12
+ property :placed_at
13
+ property :fulfil_at
14
+ property :notes
15
+ property :total
16
+ property :paid
17
+ property :product
18
+
19
+ coerce_key :lines, Kounta::Line
20
+ coerce_key :payments, Kounta::Payment
21
+
22
+ def initialize(hash={})
23
+ super(hash)
24
+ self.payments ||= []
25
+ self.lines ||= []
26
+ end
27
+
28
+ def to_hash
29
+ returning = {}
30
+ returning[:lines] = lines.map {|line| line.to_hash } if lines
31
+ returning[:payments] = payments.map {|payment| payment.to_hash } if payments
32
+ super(returning)
33
+ end
34
+
35
+ def resource_path
36
+ {companies: company_id, orders: id}
37
+ end
38
+
39
+ # we manually map these
40
+ def ignored_properties
41
+ super([:lines, :payments])
42
+ end
43
+
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,17 @@
1
+ module Kounta
2
+
3
+ class Payment < Kounta::Resource
4
+ property :company_id
5
+ property :order_id
6
+ property :method_id
7
+ property :amount
8
+ property :ref
9
+ property :method
10
+
11
+ def resource_path
12
+ {companies: company_id, orders: order_id, payments: id}
13
+ end
14
+
15
+ end
16
+
17
+ end