sellsy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef519fd21149bc969b461c0de7935d1dd151340a
4
+ data.tar.gz: ceda0918491d324d765baaa2b41ea0a12ff00253
5
+ SHA512:
6
+ metadata.gz: 84f2c7dd33b1491a5551871d2478ddc41dd08ecffeabf7155b0a3dce8bae5b2bbbced3fcbbb1f3ca98454c776d1b7770fcbd0008624b55cc05e320f390cd0368
7
+ data.tar.gz: fbbec0817ac5b68a87c1b92826686a6e19d4f9025b78a330a2a3c319e5ece516a39f0c3ed34218d49c2a46fea1cb9c0b417e25400646bcc7270381ee107e9514
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'multi_json', '~> 1.10.0' # JSON client
7
+ gem 'rest-client', '~> 1.7.0' # REST client
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "shoulda", ">= 0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0"
15
+ gem "jeweler", "~> 2.0.1"
16
+ gem "simplecov", ">= 0"
17
+ end
18
+
19
+ group :test do
20
+ gem "awesome_print", "~> 1.6.0"
21
+ gem "minitest", "~> 5.5.0"
22
+ end
@@ -0,0 +1,90 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.0)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.7)
11
+ awesome_print (1.6.1)
12
+ builder (3.2.2)
13
+ descendants_tracker (0.0.4)
14
+ thread_safe (~> 0.3, >= 0.3.1)
15
+ docile (1.1.5)
16
+ faraday (0.9.1)
17
+ multipart-post (>= 1.2, < 3)
18
+ git (1.2.9.1)
19
+ github_api (0.12.3)
20
+ addressable (~> 2.3)
21
+ descendants_tracker (~> 0.0.4)
22
+ faraday (~> 0.8, < 0.10)
23
+ hashie (>= 3.3)
24
+ multi_json (>= 1.7.5, < 2.0)
25
+ nokogiri (~> 1.6.3)
26
+ oauth2
27
+ hashie (3.4.0)
28
+ highline (1.7.1)
29
+ i18n (0.7.0)
30
+ jeweler (2.0.1)
31
+ builder
32
+ bundler (>= 1.0)
33
+ git (>= 1.2.5)
34
+ github_api
35
+ highline (>= 1.6.15)
36
+ nokogiri (>= 1.5.10)
37
+ rake
38
+ rdoc
39
+ json (1.8.2)
40
+ jwt (1.3.0)
41
+ mime-types (2.4.3)
42
+ mini_portile (0.6.2)
43
+ minitest (5.5.1)
44
+ multi_json (1.10.1)
45
+ multi_xml (0.5.5)
46
+ multipart-post (2.0.0)
47
+ netrc (0.10.2)
48
+ nokogiri (1.6.6.2)
49
+ mini_portile (~> 0.6.0)
50
+ oauth2 (1.0.0)
51
+ faraday (>= 0.8, < 0.10)
52
+ jwt (~> 1.0)
53
+ multi_json (~> 1.3)
54
+ multi_xml (~> 0.5)
55
+ rack (~> 1.2)
56
+ rack (1.6.0)
57
+ rake (10.4.2)
58
+ rdoc (3.12.2)
59
+ json (~> 1.4)
60
+ rest-client (1.7.2)
61
+ mime-types (>= 1.16, < 3.0)
62
+ netrc (~> 0.7)
63
+ shoulda (3.5.0)
64
+ shoulda-context (~> 1.0, >= 1.0.1)
65
+ shoulda-matchers (>= 1.4.1, < 3.0)
66
+ shoulda-context (1.2.1)
67
+ shoulda-matchers (2.8.0)
68
+ activesupport (>= 3.0.0)
69
+ simplecov (0.9.2)
70
+ docile (~> 1.1.0)
71
+ multi_json (~> 1.0)
72
+ simplecov-html (~> 0.9.0)
73
+ simplecov-html (0.9.0)
74
+ thread_safe (0.3.4)
75
+ tzinfo (1.2.2)
76
+ thread_safe (~> 0.1)
77
+
78
+ PLATFORMS
79
+ ruby
80
+
81
+ DEPENDENCIES
82
+ awesome_print (~> 1.6.0)
83
+ bundler (~> 1.0)
84
+ jeweler (~> 2.0.1)
85
+ minitest (~> 5.5.0)
86
+ multi_json (~> 1.10.0)
87
+ rdoc (~> 3.12)
88
+ rest-client (~> 1.7.0)
89
+ shoulda
90
+ simplecov
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 faustus7
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 all
13
+ 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 THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2015 Jens Stammers
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ # sellsy
2
+ Sellsy API Client Ruby Gem
@@ -0,0 +1,19 @@
1
+ = sellsy
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to sellsy
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2015 Jens Stammers. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "sellsy"
18
+ gem.homepage = "http://github.com/faustus7/sellsy"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Sellsy Client API}
21
+ gem.description = %Q{Ruby Gem for Sellsy}
22
+ gem.email = "jens@lacazoo.com"
23
+ gem.authors = ["Jens Stamm"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['test'].execute
39
+ end
40
+
41
+ task :default => :test
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "sellsy #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,3 @@
1
+ require 'sellsy/api'
2
+ require 'sellsy/clients'
3
+ require 'sellsy/invoices'
@@ -0,0 +1,322 @@
1
+ require 'multi_json'
2
+ require 'rest_client'
3
+
4
+ module Sellsy
5
+ class Api
6
+ class << self
7
+ attr_accessor :configuration
8
+ end
9
+
10
+ def self.configure
11
+ self.configuration ||= Configuration.new
12
+ yield(configuration)
13
+ end
14
+
15
+ def self.authentication_header
16
+ encoded_key = URI::escape(self.configuration.consumer_secret) + "&" + URI::escape(self.configuration.user_secret)
17
+ now = Time.now
18
+ oauth_params = {
19
+ 'oauth_consumer_key' => self.configuration.consumer_token,
20
+ 'oauth_token' => self.configuration.user_token,
21
+ 'oauth_nonce' => Digest::MD5.hexdigest((now.to_i + rand(0..1000)).to_s),
22
+ 'oauth_timestamp' => now.to_i.to_s,
23
+ 'oauth_signature_method' => 'PLAINTEXT',
24
+ 'oauth_version' => '1.0',
25
+ 'oauth_signature' => encoded_key
26
+ }
27
+
28
+ return 'OAuth ' + oauth_params.map { |k, v| k + '="' + v + '"' }.join(', ')
29
+ end
30
+
31
+ def self.client=(client)
32
+ payload = {
33
+ 'method' => 'Client.create',
34
+ 'params' => {
35
+ 'third' => {
36
+ 'name' => client.client_company.name,
37
+ 'email' => client.client_company.email,
38
+ 'tel' => client.client_company.landline,
39
+ 'fax' => client.client_company.fax,
40
+ 'siret' => client.client_company.billing_information.company_registration,
41
+ 'vat' => client.client_company.billing_information.vat_registration
42
+ },
43
+ 'contact' => {
44
+ 'name' => client.last_name,
45
+ 'forename' => client.first_name,
46
+ 'email' => client.email,
47
+ 'tel' => client.landline,
48
+ 'fax' => client.fax,
49
+ 'mobile' => client.mobile
50
+ },
51
+ 'address' => {
52
+ 'name' => client.address.name,
53
+ 'part1' => client.address.street,
54
+ 'part2' => client.address.addition,
55
+ 'zip' => client.address.postal_code,
56
+ 'town' => client.address.city,
57
+ 'countrycode' => "FR"
58
+ }
59
+ }
60
+ }
61
+
62
+ self.request payload
63
+ end
64
+
65
+ def self.clients
66
+ payload = {
67
+ 'method' => 'Client.getList',
68
+ 'params' => {}
69
+ }
70
+
71
+ self.request payload
72
+ end
73
+
74
+ def self.invoices=(invoice)
75
+ payload = {
76
+ 'method' => 'Document.create',
77
+ 'params' => {
78
+ 'document' => {
79
+ 'doctype' => 'doctype',
80
+ 'parentId' => 'parentId',
81
+ 'thirdid' => 'clientid',
82
+ 'displayedDate' => 'displayedDate',
83
+ 'subject' => 'document_subject',
84
+ 'notes' => 'document_notes',
85
+ 'tags' => 'document_tags',
86
+ 'displayShipAddress' => 'displayshippaddress_enum',
87
+ 'rateCategory' => 'rateCategory',
88
+ 'globalDiscount' => 'globalDiscount',
89
+ 'globalDiscountUnit' => 'globalDiscountUnit',
90
+ 'hasDoubleVat' => 'hasDoubleVat',
91
+ 'currency' => 'currency',
92
+ 'doclayout' => 'doclayout',
93
+ 'payMediums' => 'payMediums',
94
+
95
+ },
96
+ 'paydate' => {
97
+ 'id' => 'paydate_id',
98
+ 'xdays' => 'paydate_xdays',
99
+ 'endmonth' => 'paydate_endmonth',
100
+ 'scaledDetails' => 'paydate_scaledDetails',
101
+ 'custom' => 'paydate_custom'
102
+
103
+ },
104
+ 'thirdaddress' => {
105
+ 'id' => 'thirdaddress_id'
106
+ },
107
+ 'shipaddress' => {
108
+ 'id' => 'shipaddress_id'
109
+ },
110
+ 'row' => {
111
+ '1' => {
112
+ 'row_type' => 'packaging',
113
+ 'row_packaging' => 'packagin_name',
114
+ 'row_name' => 'row_name',
115
+ 'row_unitAmount' => 'row_unit_amount',
116
+ 'row_tax' => 'row_taxrate',
117
+ 'row_taxid' => 'row_taxid',
118
+ 'row_tax2id' => 'row_tax2id',
119
+ 'row_qt' => 'row_quantity',
120
+ 'row_isOption' => 'row_option',
121
+ 'row_discount' => 'row_discount',
122
+ 'row_discountUnit' => 'row_discountUnit'
123
+ },
124
+ '2' => {
125
+ 'row_type' => 'shipping',
126
+ 'row_shipping' => 'shipping_name',
127
+ 'row_name' => 'row_name',
128
+ 'row_unitAmount' => 'row_unit_amount',
129
+ 'row_tax' => 'row_taxrate',
130
+ 'row_taxid' => 'row_taxid',
131
+ 'row_tax2id' => 'row_tax2id',
132
+ 'row_qt' => 'row_quantity',
133
+ 'row_isOption' => 'row_option',
134
+ 'row_discount' => 'row_discount',
135
+ 'row_discountUnit' => 'row_discountUnit'
136
+ },
137
+ '3' => {
138
+ 'row_type' => 'item',
139
+ 'row_linkedid' => 'catalogue_id_link',
140
+ 'row_declid' => 'catalogue_declid_link',
141
+ 'row_name' => 'row_name',
142
+ 'row_notes' => 'row_notes',
143
+ 'row_unit' => 'row_unit',
144
+ 'row_unitAmount' => 'row_unit_amount',
145
+ 'row_tax' => 'row_taxrate',
146
+ 'row_taxid' => 'row_taxid',
147
+ 'row_tax2id' => 'row_tax2id',
148
+ 'row_qt' => 'row_quantity',
149
+ 'row_isOption' => 'row_option',
150
+ 'row_purchaseAmount' => 'row_purchaseAmount',
151
+ 'row_discount' => 'row_discount',
152
+ 'row_discountUnit' => 'row_discountUnit'
153
+ },
154
+ '4' => {
155
+ 'row_type' => 'once',
156
+ 'row_name' => 'row_name',
157
+ 'row_notes' => 'row_notes',
158
+ 'row_unit' => 'row_unit',
159
+ 'row_unitAmount' => 'row_unit_amount',
160
+ 'row_tax' => 'row_taxrate',
161
+ 'row_taxid' => 'row_taxid',
162
+ 'row_tax2id' => 'row_tax2id',
163
+ 'row_qt' => 'row_quantity',
164
+ 'row_isOption' => 'row_option',
165
+ 'row_discount' => 'row_discount',
166
+ 'row_discountUnit' => 'row_discountUnit'
167
+ }
168
+ }
169
+ }
170
+ }
171
+ end
172
+
173
+ def self.info
174
+ payload = {
175
+ :method => 'Infos.getInfos',
176
+ :params => {}
177
+ }
178
+
179
+ self.request payload
180
+ end
181
+
182
+ def self.request(payload)
183
+ params = {
184
+ 'request' => 1,
185
+ 'io_mode' => 'json',
186
+ 'do_in' => payload.to_json
187
+ }
188
+
189
+ puts params.to_json
190
+
191
+ RestClient.log = 'stdout'
192
+ RestClient.post 'https://apifeed.sellsy.com/0/', {:request => 1, :io_mode => 'json', 'do_in' => payload.to_json, :multipart => true}, {:authorization => self.authentication_header}
193
+ end
194
+
195
+ class Configuration
196
+ attr_accessor :consumer_secret
197
+ attr_accessor :consumer_token
198
+ attr_accessor :user_secret
199
+ attr_accessor :user_token
200
+
201
+ def initialize
202
+ end
203
+ end
204
+ end
205
+
206
+ class Invoice
207
+ attr_accessor :client_id
208
+ attr_accessor :packaging_name
209
+ attr_accessor :shipping_name
210
+ attr_accessor :unit_amount
211
+ attr_accessor :tax_rate
212
+ end
213
+
214
+ class Invoices
215
+ attr_accessor :client
216
+ attr_accessor :estimates
217
+ attr_accessor :invoices
218
+
219
+ def initialize(client)
220
+ @client = client
221
+ end
222
+
223
+ def <<(invoice)
224
+ payload = {
225
+ 'method' => 'Document.create',
226
+ 'params' => {
227
+ 'document' => {
228
+ 'doctype' => 'invoice',
229
+ # 'parentId' => 'parentId',
230
+ 'thirdid' => invoice.client_id
231
+ # 'displayedDate' => 'displayedDate',
232
+ # 'subject' => 'document_subject',
233
+ # 'notes' => 'document_notes',
234
+ # 'tags' => 'document_tags',
235
+ # 'displayShipAddress' => 'displayshippaddress_enum',
236
+ # 'rateCategory' => 'rateCategory',
237
+ # 'globalDiscount' => 'globalDiscount',
238
+ # 'globalDiscountUnit' => 'globalDiscountUnit',
239
+ # 'hasDoubleVat' => 'hasDoubleVat',
240
+ # 'currency' => 'currency',
241
+ # 'doclayout' => 'doclayout',
242
+ # 'payMediums' => 'payMediums'
243
+ },
244
+ # 'paydate' => {
245
+ # 'id' => 'paydate_id',
246
+ # 'xdays' => 'paydate_xdays',
247
+ # 'endmonth' => 'paydate_endmonth',
248
+ # 'scaledDetails' => 'paydate_scaledDetails',
249
+ # 'custom' => 'paydate_custom'
250
+ # },
251
+ # 'thirdaddress' => {
252
+ # 'id' => 'thirdaddress_id'
253
+ # },
254
+ # 'shipaddress' => {
255
+ # 'id' => 'shipaddress_id'
256
+ # },
257
+ 'row' => {
258
+ '1' => {
259
+ 'row_type' => 'packaging',
260
+ 'row_packaging' => invoice.packaging_name,
261
+ 'row_name' => 'row_name',
262
+ 'row_unitAmount' => invoice.unit_amount,
263
+ 'row_tax' => invoice.tax_rate
264
+ # 'row_taxid' => 'row_taxid',
265
+ # 'row_tax2id' => 'row_tax2id',
266
+ # 'row_qt' => 'row_quantity',
267
+ # 'row_isOption' => 'row_option',
268
+ # 'row_discount' => 'row_discount',
269
+ # 'row_discountUnit' => 'row_discountUnit'
270
+ },
271
+ '2' => {
272
+ 'row_type' => 'shipping',
273
+ 'row_shipping' => invoice.shipping_name,
274
+ # 'row_name' => 'row_name',
275
+ 'row_unitAmount' => invoice.unit_amount,
276
+ 'row_tax' => invoice.tax_rate,
277
+ # 'row_taxid' => 'row_taxid',
278
+ 'row_tax2id' => invoice.quantity
279
+ # 'row_qt' => 'row_quantity',
280
+ # 'row_isOption' => 'row_option',
281
+ # 'row_discount' => 'row_discount',
282
+ # 'row_discountUnit' => 'row_discountUnit'
283
+ }
284
+ # '3' => {
285
+ # 'row_type' => 'item',
286
+ # 'row_linkedid' => 'catalogue_id_link',
287
+ # 'row_declid' => 'catalogue_declid_link',
288
+ # 'row_name' => 'row_name',
289
+ # 'row_notes' => 'row_notes',
290
+ # 'row_unit' => 'row_unit',
291
+ # 'row_unitAmount' => 'row_unit_amount',
292
+ # 'row_tax' => 'row_taxrate',
293
+ # 'row_taxid' => 'row_taxid',
294
+ # 'row_tax2id' => 'row_tax2id',
295
+ # 'row_qt' => 'row_quantity',
296
+ # 'row_isOption' => 'row_option',
297
+ # 'row_purchaseAmount' => 'row_purchaseAmount',
298
+ # 'row_discount' => 'row_discount',
299
+ # 'row_discountUnit' => 'row_discountUnit'
300
+ # },
301
+ # '4' => {
302
+ # 'row_type' => 'once',
303
+ # 'row_name' => 'row_name',
304
+ # 'row_notes' => 'row_notes',
305
+ # 'row_unit' => 'row_unit',
306
+ # 'row_unitAmount' => 'row_unit_amount',
307
+ # 'row_tax' => 'row_taxrate',
308
+ # 'row_taxid' => 'row_taxid',
309
+ # 'row_tax2id' => 'row_tax2id',
310
+ # 'row_qt' => 'row_quantity',
311
+ # 'row_isOption' => 'row_option',
312
+ # 'row_discount' => 'row_discount',
313
+ # 'row_discountUnit' => 'row_discountUnit'
314
+ # }
315
+ }
316
+ }
317
+ }
318
+
319
+ @client.request payload
320
+ end
321
+ end
322
+ end
@@ -0,0 +1,31 @@
1
+ require 'multi_json'
2
+
3
+ module Sellsy
4
+ class Client
5
+ attr_accessor :id
6
+ attr_accessor :name
7
+
8
+ def initialize(id, name)
9
+ @id = id
10
+ @name = name
11
+ end
12
+ end
13
+
14
+ class Clients
15
+ def self.all
16
+ command = {
17
+ 'method' => 'Client.getList',
18
+ 'params' => {}
19
+ }
20
+
21
+ response = MultiJson.load(Sellsy::Api.request command)
22
+
23
+ clients = []
24
+ response['response']['result'].each do |key, value|
25
+ clients << Client.new(key, value['name'])
26
+ end
27
+
28
+ return clients
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,142 @@
1
+ require 'multi_json'
2
+
3
+ module Sellsy
4
+ class Invoice
5
+ attr_accessor :id
6
+ attr_accessor :client_id
7
+ attr_accessor :packaging_name
8
+ attr_accessor :shipping_name
9
+ attr_accessor :amount
10
+ attr_accessor :unit_amount
11
+ attr_accessor :tax_rate
12
+ end
13
+
14
+ class Invoices
15
+ attr_accessor :estimates
16
+ attr_accessor :invoices
17
+
18
+ def initialize
19
+ end
20
+
21
+ def self.all
22
+ command = {
23
+ 'method' => 'Document.getList',
24
+ 'params' => {
25
+ 'doctype' => 'invoice'
26
+ }
27
+ }
28
+
29
+ response = MultiJson.load(Sellsy::Api.request command)
30
+
31
+ invoices = []
32
+ # ap response
33
+ response['response']['result'].each do |key, value|
34
+ invoice = Invoice.new
35
+ invoice.id = value['id']
36
+ invoice.amount = value['rowsAmount']
37
+ invoices << invoice
38
+ end
39
+
40
+ return invoices
41
+ end
42
+
43
+ def <<(invoice)
44
+ command = {
45
+ 'method' => 'Document.create',
46
+ 'params' => {
47
+ 'document' => {
48
+ 'doctype' => 'invoice',
49
+ # 'parentId' => 'parentId',
50
+ 'thirdid' => invoice.client_id
51
+ # 'displayedDate' => 'displayedDate',
52
+ # 'subject' => 'document_subject',
53
+ # 'notes' => 'document_notes',
54
+ # 'tags' => 'document_tags',
55
+ # 'displayShipAddress' => 'displayshippaddress_enum',
56
+ # 'rateCategory' => 'rateCategory',
57
+ # 'globalDiscount' => 'globalDiscount',
58
+ # 'globalDiscountUnit' => 'globalDiscountUnit',
59
+ # 'hasDoubleVat' => 'hasDoubleVat',
60
+ # 'currency' => 'currency',
61
+ # 'doclayout' => 'doclayout',
62
+ # 'payMediums' => 'payMediums'
63
+ },
64
+ # 'paydate' => {
65
+ # 'id' => 'paydate_id',
66
+ # 'xdays' => 'paydate_xdays',
67
+ # 'endmonth' => 'paydate_endmonth',
68
+ # 'scaledDetails' => 'paydate_scaledDetails',
69
+ # 'custom' => 'paydate_custom'
70
+ # },
71
+ # 'thirdaddress' => {
72
+ # 'id' => 'thirdaddress_id'
73
+ # },
74
+ # 'shipaddress' => {
75
+ # 'id' => 'shipaddress_id'
76
+ # },
77
+ 'row' => {
78
+ '1' => {
79
+ 'row_type' => 'packaging',
80
+ 'row_packaging' => invoice.packaging_name,
81
+ 'row_name' => 'row_name',
82
+ 'row_unitAmount' => invoice.unit_amount,
83
+ 'row_tax' => invoice.tax_rate
84
+ # 'row_taxid' => 'row_taxid',
85
+ # 'row_tax2id' => 'row_tax2id',
86
+ # 'row_qt' => 'row_quantity',
87
+ # 'row_isOption' => 'row_option',
88
+ # 'row_discount' => 'row_discount',
89
+ # 'row_discountUnit' => 'row_discountUnit'
90
+ },
91
+ '2' => {
92
+ 'row_type' => 'shipping',
93
+ 'row_shipping' => invoice.shipping_name,
94
+ # 'row_name' => 'row_name',
95
+ 'row_unitAmount' => invoice.unit_amount,
96
+ 'row_tax' => invoice.tax_rate,
97
+ # 'row_taxid' => 'row_taxid',
98
+ 'row_tax2id' => invoice.quantity
99
+ # 'row_qt' => 'row_quantity',
100
+ # 'row_isOption' => 'row_option',
101
+ # 'row_discount' => 'row_discount',
102
+ # 'row_discountUnit' => 'row_discountUnit'
103
+ }
104
+ # '3' => {
105
+ # 'row_type' => 'item',
106
+ # 'row_linkedid' => 'catalogue_id_link',
107
+ # 'row_declid' => 'catalogue_declid_link',
108
+ # 'row_name' => 'row_name',
109
+ # 'row_notes' => 'row_notes',
110
+ # 'row_unit' => 'row_unit',
111
+ # 'row_unitAmount' => 'row_unit_amount',
112
+ # 'row_tax' => 'row_taxrate',
113
+ # 'row_taxid' => 'row_taxid',
114
+ # 'row_tax2id' => 'row_tax2id',
115
+ # 'row_qt' => 'row_quantity',
116
+ # 'row_isOption' => 'row_option',
117
+ # 'row_purchaseAmount' => 'row_purchaseAmount',
118
+ # 'row_discount' => 'row_discount',
119
+ # 'row_discountUnit' => 'row_discountUnit'
120
+ # },
121
+ # '4' => {
122
+ # 'row_type' => 'once',
123
+ # 'row_name' => 'row_name',
124
+ # 'row_notes' => 'row_notes',
125
+ # 'row_unit' => 'row_unit',
126
+ # 'row_unitAmount' => 'row_unit_amount',
127
+ # 'row_tax' => 'row_taxrate',
128
+ # 'row_taxid' => 'row_taxid',
129
+ # 'row_tax2id' => 'row_tax2id',
130
+ # 'row_qt' => 'row_quantity',
131
+ # 'row_isOption' => 'row_option',
132
+ # 'row_discount' => 'row_discount',
133
+ # 'row_discountUnit' => 'row_discountUnit'
134
+ # }
135
+ }
136
+ }
137
+ }
138
+
139
+ Sellsy::Api.request command
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,32 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ require 'rubygems'
18
+ require 'bundler'
19
+ begin
20
+ Bundler.setup(:default, :development)
21
+ rescue Bundler::BundlerError => e
22
+ $stderr.puts e.message
23
+ $stderr.puts "Run `bundle install` to install missing gems"
24
+ exit e.status_code
25
+ end
26
+ require "minitest/autorun"
27
+ require 'shoulda'
28
+ require "awesome_print"
29
+
30
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
31
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
32
+ require 'sellsy'
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ class TestSellsy < Minitest::Test
4
+ def setup
5
+ Sellsy::Api.configure do |config|
6
+ config.consumer_token = ENV['SELLSY_CONSUMER_TOKEN']
7
+ config.consumer_secret = ENV['SELLSY_CONSUMER_SECRET']
8
+ config.user_token = ENV['SELLSY_USER_TOKEN']
9
+ config.user_secret = ENV['SELLSY_USER_SECRET']
10
+ end
11
+
12
+ @invoices = Sellsy
13
+ end
14
+
15
+ def test_that_all_clients
16
+ @clients = Sellsy::Clients.all
17
+
18
+ ap @clients
19
+
20
+ refute_equal 0, @clients.length
21
+ end
22
+
23
+ def test_that_all_invocies
24
+ @invoices = Sellsy::Invoices.all
25
+
26
+ ap @invoices
27
+
28
+ refute_equal 0, @invoices.length
29
+ end
30
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sellsy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jens Stamm
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: shoulda
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.0.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.0.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Ruby Gem for Sellsy
112
+ email: jens@lacazoo.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files:
116
+ - LICENSE
117
+ - LICENSE.txt
118
+ - README.md
119
+ - README.rdoc
120
+ files:
121
+ - ".document"
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE
125
+ - LICENSE.txt
126
+ - README.md
127
+ - README.rdoc
128
+ - Rakefile
129
+ - VERSION
130
+ - lib/sellsy.rb
131
+ - lib/sellsy/api.rb
132
+ - lib/sellsy/clients.rb
133
+ - lib/sellsy/invoices.rb
134
+ - test/helper.rb
135
+ - test/test_sellsy.rb
136
+ homepage: http://github.com/faustus7/sellsy
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.4.3
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: Sellsy Client API
160
+ test_files: []