insales_api 0.0.10 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/README +31 -2
  4. data/insales_api.gemspec +1 -0
  5. data/lib/active_resource/singleton.rb +114 -0
  6. data/lib/insales_api/{resources/account.rb → account.rb} +0 -0
  7. data/lib/insales_api/app.rb +3 -3
  8. data/lib/insales_api/{resources/application_widget.rb → application_widget.rb} +0 -0
  9. data/lib/insales_api/asset.rb +3 -0
  10. data/lib/insales_api/{resources/base.rb → base.rb} +1 -1
  11. data/lib/insales_api/{resources/category.rb → category.rb} +0 -0
  12. data/lib/insales_api/{resources/client.rb → client.rb} +0 -0
  13. data/lib/insales_api/{resources/collect.rb → collect.rb} +0 -0
  14. data/lib/insales_api/{resources/collection.rb → collection.rb} +0 -0
  15. data/lib/insales_api/{resources/delivery_variant.rb → delivery_variant.rb} +0 -0
  16. data/lib/insales_api/domain.rb +3 -0
  17. data/lib/insales_api/{resources/field.rb → field.rb} +0 -0
  18. data/lib/insales_api/file.rb +3 -0
  19. data/lib/insales_api/{resources/js_tag.rb → js_tag.rb} +0 -0
  20. data/lib/insales_api/{resources/option_name.rb → option_name.rb} +0 -0
  21. data/lib/insales_api/{resources/option_value.rb → option_value.rb} +0 -0
  22. data/lib/insales_api/{resources/order.rb → order.rb} +0 -0
  23. data/lib/insales_api/{resources/order_line.rb → order_line.rb} +0 -0
  24. data/lib/insales_api/page.rb +3 -0
  25. data/lib/insales_api/password.rb +0 -1
  26. data/lib/insales_api/{resources/payment_gateway.rb → payment_gateway.rb} +0 -0
  27. data/lib/insales_api/{resources/product.rb → product.rb} +0 -0
  28. data/lib/insales_api/recurring_application_charge.rb +5 -0
  29. data/lib/insales_api/theme.rb +3 -0
  30. data/lib/insales_api/variant.rb +11 -0
  31. data/lib/insales_api/version.rb +1 -1
  32. data/lib/insales_api/{resources/webhook.rb → webhook.rb} +0 -0
  33. data/lib/insales_api.rb +36 -6
  34. metadata +54 -37
  35. data/lib/insales_api/resources/variant.rb +0 -5
  36. data/lib/insales_api/resources.rb +0 -19
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21c7b7e853b3998b60bd9e067abc75be2837608d
4
+ data.tar.gz: 1e3cdaf7a448b016227d6fc8f5b2f4a82ae48572
5
+ SHA512:
6
+ metadata.gz: 7f62cd468de7f1da9773068404b6b715a420d68eb106b2b3a3f15a9cd18da7cc3bc6c47d3aa4bd45cd90c751c2243687958b076b0a32fcc5b99a5c25fc4c56de
7
+ data.tar.gz: ac1324ae0d02fb0995752d05987f764e05cfda89afabc1c17e7ebe5ea60e6ad0f2fef0aa3338267cb2b4a3bfcb350deb537f264427091925b6347ee3eb94a9c8
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.13
2
+
3
+ * ActiveResource::Singleton backport.
4
+ * Fix for multiple InsalesApi::Apps child-classes in single app.
data/README CHANGED
@@ -1,3 +1,32 @@
1
- add in your Gemfile
1
+ # InsalesApi gem
2
2
 
3
- require 'insales_api'
3
+ Insales api client based on [ActiveResource](https://github.com/rails/activeresource).
4
+
5
+ Rails application example is [here](https://github.com/insales/insales_app).
6
+
7
+ ## Install
8
+
9
+ Add to Gemfile:
10
+
11
+ ```ruby
12
+ gem 'insales_api'
13
+ ```
14
+
15
+ ## Initialize
16
+
17
+ ```ruby
18
+ class MyApp < InsalesApi::App
19
+ self.api_key = 'api_key'
20
+ end
21
+
22
+ MyApp.configure_api('domain', 'password')
23
+ ```
24
+
25
+ ## Use
26
+
27
+ ```ruby
28
+ order = InsaleApi::Order.find 123
29
+
30
+ # singleton resources
31
+ account = InsaleApi::Account.find
32
+ ```
data/insales_api.gemspec CHANGED
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
 
20
+ s.add_dependency("activesupport", [">= 3.0.0"])
20
21
  s.add_dependency("activeresource", [">= 3.0.0"])
21
22
  s.add_development_dependency "rspec"
22
23
  end
@@ -0,0 +1,114 @@
1
+ module ActiveResource
2
+ module Singleton
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ attr_writer :singleton_name
7
+
8
+ def singleton_name
9
+ @singleton_name ||= model_name.element
10
+ end
11
+
12
+ # Gets the singleton path for the object. If the +query_options+ parameter is omitted, Rails
13
+ # will split from the \prefix options.
14
+ #
15
+ # ==== Options
16
+ # +prefix_options+ - A \hash to add a \prefix to the request for nested URLs (e.g., <tt>:account_id => 19</tt>
17
+ # would yield a URL like <tt>/accounts/19/purchases.json</tt>).
18
+ # +query_options+ - A \hash to add items to the query string for the request.
19
+ #
20
+ # ==== Examples
21
+ # Weather.singleton_path
22
+ # # => /weather.json
23
+ #
24
+ # class Inventory < ActiveResource::Base
25
+ # self.site = "https://37s.sunrise.com"
26
+ # self.prefix = "/products/:product_id/"
27
+ # end
28
+ #
29
+ # Inventory.singleton_path(:product_id => 5)
30
+ # # => /products/5/inventory.json
31
+ #
32
+ # Inventory.singleton_path({:product_id => 5}, {:sold => true})
33
+ # # => /products/5/inventory.json?sold=true
34
+ #
35
+ def singleton_path(prefix_options = {}, query_options = nil)
36
+ check_prefix_options(prefix_options)
37
+
38
+ prefix_options, query_options = split_options(prefix_options) if query_options.nil?
39
+ "#{prefix(prefix_options)}#{singleton_name}.#{format.extension}#{query_string(query_options)}"
40
+ end
41
+
42
+ # Core method for finding singleton resources.
43
+ #
44
+ # ==== Arguments
45
+ # Takes a single argument of options
46
+ #
47
+ # ==== Options
48
+ # * <tt>:params</tt> - Sets the query and \prefix (nested URL) parameters.
49
+ #
50
+ # ==== Examples
51
+ # Weather.find
52
+ # # => GET /weather.json
53
+ #
54
+ # Weather.find(:params => {:degrees => 'fahrenheit'})
55
+ # # => GET /weather.json?degrees=fahrenheit
56
+ #
57
+ # == Failure or missing data
58
+ # A failure to find the requested object raises a ResourceNotFound
59
+ # exception.
60
+ #
61
+ # Inventory.find
62
+ # # => raises ResourceNotFound
63
+ def find(options={})
64
+ find_singleton(options)
65
+ end
66
+
67
+ private
68
+ # Find singleton resource
69
+ def find_singleton(options)
70
+ prefix_options, query_options = split_options(options[:params])
71
+
72
+ path = singleton_path(prefix_options, query_options)
73
+ resp = self.format.decode(self.connection.get(path, self.headers).body)
74
+ instantiate_record(resp, {})
75
+ end
76
+
77
+ end
78
+ # Deletes the resource from the remove service.
79
+ #
80
+ # ==== Examples
81
+ # weather = Weather.find
82
+ # weather.destroy
83
+ # Weather.find # 404 (Resource Not Found)
84
+ def destroy
85
+ connection.delete(singleton_path, self.class.headers)
86
+ end
87
+
88
+
89
+ protected
90
+
91
+ # Update the resource on the remote service
92
+ def update
93
+ connection.put(singleton_path(prefix_options), encode, self.class.headers).tap do |response|
94
+ load_attributes_from_response(response)
95
+ end
96
+ end
97
+
98
+ # Create (i.e. \save to the remote service) the \new resource.
99
+ def create
100
+ connection.post(singleton_path, encode, self.class.headers).tap do |response|
101
+ self.id = id_from_response(response)
102
+ load_attributes_from_response(response)
103
+ end
104
+ end
105
+
106
+ private
107
+
108
+ def singleton_path(options = nil)
109
+ self.class.singleton_path(options || prefix_options)
110
+ end
111
+
112
+ end
113
+
114
+ end
@@ -1,7 +1,6 @@
1
- require 'digest/md5'
2
1
  module InsalesApi
3
2
  class App
4
- cattr_accessor :api_key, :api_host, :api_secret, :api_autologin_path
3
+ class_attribute :api_key, :api_host, :api_secret, :api_autologin_path
5
4
  attr_reader :authorized, :auth_token, :shop, :password
6
5
 
7
6
  def initialize(shop, password)
@@ -12,7 +11,8 @@ module InsalesApi
12
11
 
13
12
  def authorization_url
14
13
  store_auth_token
15
- "http://#{shop}/admin/applications/#{self.class.api_key}/login?token=#{salt}&login=http://#{self.class.api_host}/#{self.class.api_autologin_path}"
14
+ "http://#{shop}/admin/applications/#{self.class.api_key}/login?" \
15
+ "token=#{salt}&login=http://#{self.class.api_host}/#{self.class.api_autologin_path}"
16
16
  end
17
17
 
18
18
  def store_auth_token
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class Asset < Base; end
3
+ end
@@ -6,7 +6,7 @@ module InsalesApi
6
6
  self.user = api_key
7
7
  self.site = "http://#{shop}/admin/"
8
8
  self.password = password
9
- return
9
+ nil
10
10
  end
11
11
  end
12
12
  end
File without changes
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class Domain < Base; end
3
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class File < Base; end
3
+ end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class Page < Base; end
3
+ end
@@ -1,4 +1,3 @@
1
- require 'digest/md5'
2
1
  module InsalesApi
3
2
  module Password
4
3
  def self.create(secret, token)
@@ -0,0 +1,5 @@
1
+ module InsalesApi
2
+ class RecurringApplicationCharge < Base
3
+ include ActiveResource::Singleton
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module InsalesApi
2
+ class Theme < Base; end
3
+ end
@@ -0,0 +1,11 @@
1
+ module InsalesApi
2
+ class Variant < Base
3
+ self.prefix = "/admin/products/:product_id/"
4
+
5
+ # variants_attrs - массив c модицикациями в формате [{:id => 1, :price => 340, :quantity => 4}, {:id => 2, :price => 350, :quantity => 5}]
6
+ def self.group_update variants_attrs
7
+ connection.put("/admin/products/variants_group_update.xml", { :variants => variants_attrs }.to_xml, headers)
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module InsalesApi
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.13"
3
3
  end
data/lib/insales_api.rb CHANGED
@@ -1,10 +1,40 @@
1
- require "active_resource"
2
- require "digest/md5"
1
+ require 'active_support/core_ext'
2
+ require 'active_resource'
3
+ # backport from 4.0
4
+ require 'active_resource/singleton' unless ActiveResource.const_defined?(:Singleton, false)
5
+ require 'digest/md5'
3
6
 
4
7
  module InsalesApi
8
+ extend ActiveSupport::Autoload
5
9
 
6
- end
10
+ eager_autoload do
11
+ autoload :Version
12
+ autoload :App
13
+ autoload :Password
7
14
 
8
- require "insales_api/resources"
9
- require "insales_api/app"
10
- require "insales_api/password"
15
+ autoload :Base
16
+ autoload :Account
17
+ autoload :Category
18
+ autoload :Client
19
+ autoload :Collection
20
+ autoload :Collect
21
+ autoload :OptionName
22
+ autoload :OptionValue
23
+ autoload :Product
24
+ autoload :Variant
25
+ autoload :Webhook
26
+ autoload :Order
27
+ autoload :OrderLine
28
+ autoload :ApplicationWidget
29
+ autoload :Field
30
+ autoload :DeliveryVariant
31
+ autoload :PaymentGateway
32
+ autoload :JsTag
33
+ autoload :Domain
34
+ autoload :Page
35
+ autoload :Theme
36
+ autoload :Asset
37
+ autoload :RecurringApplicationCharge
38
+ autoload :File
39
+ end
40
+ end
metadata CHANGED
@@ -1,46 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insales_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
5
- prerelease:
4
+ version: 0.0.13
6
5
  platform: ruby
7
6
  authors:
8
7
  - InSales
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-11 00:00:00.000000000 Z
11
+ date: 2013-08-23 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.0.0
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: activeresource
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ! '>='
31
+ - - '>='
20
32
  - !ruby/object:Gem::Version
21
33
  version: 3.0.0
22
34
  type: :runtime
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ! '>='
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: 3.0.0
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rspec
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  description: Gem for accessing the InSales REST web services
@@ -50,57 +59,65 @@ extensions: []
50
59
  extra_rdoc_files: []
51
60
  files:
52
61
  - .gitignore
62
+ - CHANGELOG.md
53
63
  - Gemfile
54
64
  - README
55
65
  - Rakefile
56
66
  - insales_api.gemspec
67
+ - lib/active_resource/singleton.rb
57
68
  - lib/insales_api.rb
69
+ - lib/insales_api/account.rb
58
70
  - lib/insales_api/app.rb
71
+ - lib/insales_api/application_widget.rb
72
+ - lib/insales_api/asset.rb
73
+ - lib/insales_api/base.rb
74
+ - lib/insales_api/category.rb
75
+ - lib/insales_api/client.rb
76
+ - lib/insales_api/collect.rb
77
+ - lib/insales_api/collection.rb
78
+ - lib/insales_api/delivery_variant.rb
79
+ - lib/insales_api/domain.rb
80
+ - lib/insales_api/field.rb
81
+ - lib/insales_api/file.rb
82
+ - lib/insales_api/js_tag.rb
83
+ - lib/insales_api/option_name.rb
84
+ - lib/insales_api/option_value.rb
85
+ - lib/insales_api/order.rb
86
+ - lib/insales_api/order_line.rb
87
+ - lib/insales_api/page.rb
59
88
  - lib/insales_api/password.rb
60
- - lib/insales_api/resources.rb
61
- - lib/insales_api/resources/account.rb
62
- - lib/insales_api/resources/application_widget.rb
63
- - lib/insales_api/resources/base.rb
64
- - lib/insales_api/resources/category.rb
65
- - lib/insales_api/resources/client.rb
66
- - lib/insales_api/resources/collect.rb
67
- - lib/insales_api/resources/collection.rb
68
- - lib/insales_api/resources/delivery_variant.rb
69
- - lib/insales_api/resources/field.rb
70
- - lib/insales_api/resources/js_tag.rb
71
- - lib/insales_api/resources/option_name.rb
72
- - lib/insales_api/resources/option_value.rb
73
- - lib/insales_api/resources/order.rb
74
- - lib/insales_api/resources/order_line.rb
75
- - lib/insales_api/resources/payment_gateway.rb
76
- - lib/insales_api/resources/product.rb
77
- - lib/insales_api/resources/variant.rb
78
- - lib/insales_api/resources/webhook.rb
89
+ - lib/insales_api/payment_gateway.rb
90
+ - lib/insales_api/product.rb
91
+ - lib/insales_api/recurring_application_charge.rb
92
+ - lib/insales_api/theme.rb
93
+ - lib/insales_api/variant.rb
79
94
  - lib/insales_api/version.rb
95
+ - lib/insales_api/webhook.rb
80
96
  - spec/lib/insales_app_spec.rb
81
97
  - spec/spec_helper.rb
82
98
  homepage: http://wiki.insales.ru/wiki/%D0%9A%D0%B0%D0%BA_%D0%B8%D0%BD%D1%82%D0%B5%D0%B3%D1%80%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D1%82%D1%8C%D1%81%D1%8F_%D1%81_InSales
83
99
  licenses: []
100
+ metadata: {}
84
101
  post_install_message:
85
102
  rdoc_options: []
86
103
  require_paths:
87
104
  - lib
88
105
  required_ruby_version: !ruby/object:Gem::Requirement
89
- none: false
90
106
  requirements:
91
- - - ! '>='
107
+ - - '>='
92
108
  - !ruby/object:Gem::Version
93
109
  version: '0'
94
110
  required_rubygems_version: !ruby/object:Gem::Requirement
95
- none: false
96
111
  requirements:
97
- - - ! '>='
112
+ - - '>='
98
113
  - !ruby/object:Gem::Version
99
114
  version: '0'
100
115
  requirements: []
101
116
  rubyforge_project: insales_api
102
- rubygems_version: 1.8.24
117
+ rubygems_version: 2.0.3
103
118
  signing_key:
104
- specification_version: 3
119
+ specification_version: 4
105
120
  summary: Gem for accessing the InSales REST web services
106
- test_files: []
121
+ test_files:
122
+ - spec/lib/insales_app_spec.rb
123
+ - spec/spec_helper.rb
@@ -1,5 +0,0 @@
1
- module InsalesApi
2
- class Variant < Base
3
- self.prefix = "/admin/products/:product_id/"
4
- end
5
- end
@@ -1,19 +0,0 @@
1
- require "insales_api/resources/base.rb"
2
- require "insales_api/resources/account.rb"
3
- require "insales_api/resources/category.rb"
4
- require "insales_api/resources/client.rb"
5
- require "insales_api/resources/collection.rb"
6
- require "insales_api/resources/collect.rb"
7
- require "insales_api/resources/option_name.rb"
8
- require "insales_api/resources/option_value.rb"
9
- require "insales_api/resources/product.rb"
10
- require "insales_api/resources/variant.rb"
11
- require "insales_api/resources/webhook.rb"
12
- require "insales_api/resources/order.rb"
13
- require "insales_api/resources/order_line.rb"
14
- require "insales_api/resources/application_widget.rb"
15
- require "insales_api/resources/field.rb"
16
- require "insales_api/resources/delivery_variant.rb"
17
- require "insales_api/resources/payment_gateway.rb"
18
- require "insales_api/resources/js_tag.rb"
19
-