desertcart 1.0.0

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.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/main.yml +18 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/CHANGELOG.md +5 -0
  6. data/Gemfile +10 -0
  7. data/Gemfile.lock +138 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +107 -0
  10. data/Rakefile +8 -0
  11. data/bin/console +15 -0
  12. data/bin/setup +8 -0
  13. data/desertcart.gemspec +34 -0
  14. data/lib/desertcart/authentication_token/deserializer.rb +21 -0
  15. data/lib/desertcart/authentication_token/operations/find.rb +20 -0
  16. data/lib/desertcart/authentication_token/serializer.rb +21 -0
  17. data/lib/desertcart/client.rb +65 -0
  18. data/lib/desertcart/config.rb +14 -0
  19. data/lib/desertcart/deserializer.rb +9 -0
  20. data/lib/desertcart/marketplace/authorizations/operations/create.rb +30 -0
  21. data/lib/desertcart/marketplace/authorizations/serializer.rb +14 -0
  22. data/lib/desertcart/marketplace/movement/deserializer.rb +15 -0
  23. data/lib/desertcart/marketplace/movement/operations/create.rb +26 -0
  24. data/lib/desertcart/marketplace/movement/serializer.rb +20 -0
  25. data/lib/desertcart/marketplace/order_item/deserializer.rb +38 -0
  26. data/lib/desertcart/marketplace/order_item/operations/find.rb +44 -0
  27. data/lib/desertcart/marketplace/order_item/operations/update.rb +44 -0
  28. data/lib/desertcart/marketplace/order_item/searcher.rb +21 -0
  29. data/lib/desertcart/marketplace/order_item/serializer.rb +34 -0
  30. data/lib/desertcart/marketplace/order_item_acceptance/operations/create.rb +31 -0
  31. data/lib/desertcart/marketplace/order_item_acceptance/serializer.rb +15 -0
  32. data/lib/desertcart/marketplace/order_item_rejection/operations/create.rb +31 -0
  33. data/lib/desertcart/marketplace/order_item_rejection/serializer.rb +15 -0
  34. data/lib/desertcart/marketplace/pending_order_items/searcher.rb +25 -0
  35. data/lib/desertcart/marketplace/registration/operations/create.rb +34 -0
  36. data/lib/desertcart/marketplace/registration/serializer.rb +13 -0
  37. data/lib/desertcart/marketplace/shipping_address/deserializer.rb +18 -0
  38. data/lib/desertcart/marketplace/store/deserializer.rb +12 -0
  39. data/lib/desertcart/marketplace/store/operations/find.rb +22 -0
  40. data/lib/desertcart/marketplace/store/serializer.rb +12 -0
  41. data/lib/desertcart/operation/create.rb +49 -0
  42. data/lib/desertcart/operation/find.rb +63 -0
  43. data/lib/desertcart/operation/update.rb +49 -0
  44. data/lib/desertcart/operation.rb +39 -0
  45. data/lib/desertcart/resource.rb +6 -0
  46. data/lib/desertcart/resources/authentication_token.rb +14 -0
  47. data/lib/desertcart/resources/marketplace/authorization.rb +9 -0
  48. data/lib/desertcart/resources/marketplace/movement.rb +16 -0
  49. data/lib/desertcart/resources/marketplace/order_item.rb +34 -0
  50. data/lib/desertcart/resources/marketplace/order_item_acceptance.rb +10 -0
  51. data/lib/desertcart/resources/marketplace/order_item_rejection.rb +10 -0
  52. data/lib/desertcart/resources/marketplace/registration.rb +11 -0
  53. data/lib/desertcart/resources/marketplace/shipping_address.rb +15 -0
  54. data/lib/desertcart/resources/marketplace/store.rb +10 -0
  55. data/lib/desertcart/resources/session.rb +8 -0
  56. data/lib/desertcart/resources/user.rb +7 -0
  57. data/lib/desertcart/searcher.rb +70 -0
  58. data/lib/desertcart/serializer.rb +9 -0
  59. data/lib/desertcart/session/operations/create.rb +27 -0
  60. data/lib/desertcart/session/operations/find.rb +27 -0
  61. data/lib/desertcart/session/serializer.rb +10 -0
  62. data/lib/desertcart/user/deserializer.rb +10 -0
  63. data/lib/desertcart/user/serializer.rb +10 -0
  64. data/lib/desertcart/version.rb +5 -0
  65. data/lib/desertcart.rb +7 -0
  66. metadata +125 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 96786e0639aedbd1ea6b5385a9e8365233c130e03d42e5a71c0c9f36e5cf788f
4
+ data.tar.gz: 33e199b3fd1ddc4ec40727165de105473a995bb6c6c97a45e11daf3dd2bfe41c
5
+ SHA512:
6
+ metadata.gz: 7982f5aa663b627b53c3b69c9e1f391bd397ed65f15b001929bd277cbc34ca28d69faef378eaa34a8e355344384d2ee06be1e71253793dfd48734b64fbacffb5
7
+ data.tar.gz: aef6ebc66f95aacae392da90c7e180f5c550344fae01f32684131733a201e6b5345332308f16003dde81fcf6217ed543af321aa56aa5e5609288ccd4adba221e
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.15
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [1.0.0] - 2021-09-01
4
+
5
+ - Initial release of first stable version.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in desertcart.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,138 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ desertcart (1.0.0)
5
+ ledger_sync (~> 2.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.1.4.1)
11
+ activesupport (= 6.1.4.1)
12
+ activesupport (6.1.4.1)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 1.6, < 2)
15
+ minitest (>= 5.1)
16
+ tzinfo (~> 2.0)
17
+ zeitwerk (~> 2.3)
18
+ colorize (0.8.1)
19
+ concurrent-ruby (1.1.9)
20
+ diff-lcs (1.4.4)
21
+ dry-configurable (0.12.1)
22
+ concurrent-ruby (~> 1.0)
23
+ dry-core (~> 0.5, >= 0.5.0)
24
+ dry-container (0.8.0)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-configurable (~> 0.1, >= 0.1.3)
27
+ dry-core (0.7.1)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-equalizer (0.3.0)
30
+ dry-inflector (0.2.1)
31
+ dry-initializer (3.0.4)
32
+ dry-logic (1.2.0)
33
+ concurrent-ruby (~> 1.0)
34
+ dry-core (~> 0.5, >= 0.5)
35
+ dry-schema (1.5.6)
36
+ concurrent-ruby (~> 1.0)
37
+ dry-configurable (~> 0.8, >= 0.8.3)
38
+ dry-core (~> 0.4)
39
+ dry-equalizer (~> 0.2)
40
+ dry-initializer (~> 3.0)
41
+ dry-logic (~> 1.0)
42
+ dry-types (~> 1.4)
43
+ dry-types (1.5.1)
44
+ concurrent-ruby (~> 1.0)
45
+ dry-container (~> 0.3)
46
+ dry-core (~> 0.5, >= 0.5)
47
+ dry-inflector (~> 0.1, >= 0.1.2)
48
+ dry-logic (~> 1.0, >= 1.0.2)
49
+ dry-validation (1.5.6)
50
+ concurrent-ruby (~> 1.0)
51
+ dry-container (~> 0.7, >= 0.7.1)
52
+ dry-core (~> 0.4)
53
+ dry-equalizer (~> 0.2)
54
+ dry-initializer (~> 3.0)
55
+ dry-schema (~> 1.5, >= 1.5.2)
56
+ faraday (1.7.1)
57
+ faraday-em_http (~> 1.0)
58
+ faraday-em_synchrony (~> 1.0)
59
+ faraday-excon (~> 1.1)
60
+ faraday-httpclient (~> 1.0.1)
61
+ faraday-net_http (~> 1.0)
62
+ faraday-net_http_persistent (~> 1.1)
63
+ faraday-patron (~> 1.0)
64
+ faraday-rack (~> 1.0)
65
+ multipart-post (>= 1.2, < 3)
66
+ ruby2_keywords (>= 0.0.4)
67
+ faraday-detailed_logger (2.3.0)
68
+ faraday (>= 0.8, < 2)
69
+ faraday-em_http (1.0.0)
70
+ faraday-em_synchrony (1.0.0)
71
+ faraday-excon (1.1.0)
72
+ faraday-httpclient (1.0.1)
73
+ faraday-net_http (1.0.1)
74
+ faraday-net_http_persistent (1.2.0)
75
+ faraday-patron (1.0.0)
76
+ faraday-rack (1.0.0)
77
+ faraday_middleware (1.1.0)
78
+ faraday (~> 1.0)
79
+ fingerprintable (1.2.1)
80
+ colorize
81
+ i18n (1.8.10)
82
+ concurrent-ruby (~> 1.0)
83
+ ledger_sync (2.2.0)
84
+ activemodel
85
+ colorize
86
+ dry-schema (~> 1.5.4)
87
+ dry-validation (~> 1.5.6)
88
+ faraday
89
+ faraday-detailed_logger
90
+ faraday_middleware
91
+ fingerprintable (>= 1.2.1)
92
+ nokogiri
93
+ openssl (~> 2.2.0)
94
+ pd_ruby
95
+ rack (~> 2.2.3)
96
+ resonad
97
+ simply_serializable (>= 1.5.1)
98
+ minitest (5.14.4)
99
+ multipart-post (2.1.1)
100
+ nokogiri (1.12.4-x86_64-linux)
101
+ racc (~> 1.4)
102
+ openssl (2.2.0)
103
+ pd_ruby (0.2.3)
104
+ colorize
105
+ racc (1.5.2)
106
+ rack (2.2.3)
107
+ rake (13.0.6)
108
+ resonad (1.4.0)
109
+ rspec (3.10.0)
110
+ rspec-core (~> 3.10.0)
111
+ rspec-expectations (~> 3.10.0)
112
+ rspec-mocks (~> 3.10.0)
113
+ rspec-core (3.10.1)
114
+ rspec-support (~> 3.10.0)
115
+ rspec-expectations (3.10.1)
116
+ diff-lcs (>= 1.2.0, < 2.0)
117
+ rspec-support (~> 3.10.0)
118
+ rspec-mocks (3.10.2)
119
+ diff-lcs (>= 1.2.0, < 2.0)
120
+ rspec-support (~> 3.10.0)
121
+ rspec-support (3.10.2)
122
+ ruby2_keywords (0.0.5)
123
+ simply_serializable (1.5.1)
124
+ fingerprintable (>= 1.2.1)
125
+ tzinfo (2.0.4)
126
+ concurrent-ruby (~> 1.0)
127
+ zeitwerk (2.4.2)
128
+
129
+ PLATFORMS
130
+ x86_64-linux
131
+
132
+ DEPENDENCIES
133
+ desertcart!
134
+ rake (~> 13.0)
135
+ rspec (~> 3.0)
136
+
137
+ BUNDLED WITH
138
+ 2.2.15
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Jozef Vaclavik
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.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Desertcart
2
+
3
+ This gem allows you to talk with Desertcart and its Marketplace API. It is build on top of ledger_sync.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'desertcart'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install desertcart
20
+
21
+ ## Usage
22
+
23
+ ### Authentication and Authorization
24
+
25
+ Get tokens from API by signing in.
26
+
27
+ ```ruby
28
+ require 'desertcart'
29
+
30
+ client = Desertcart::Client.new
31
+
32
+ resource = Desertcart::Session.new(login: 'EMAIL', password: 'password')
33
+
34
+ operation = Desertcart::Session::Operations::Create.new(client: client, resource: resource)
35
+ operation.perform
36
+
37
+ Setting['DESERTCART_USER_TOKEN'] = operation.result.resource.token
38
+ Setting['DESERTCART_USER_ID'] = operation.result.resource.user.ledger_id
39
+ ```
40
+
41
+ Once you have tokens, go ahead and get tokens for your store (id: 1)
42
+ ```ruby
43
+ client = Desertcart::Client.new(user_id: Setting['DESERTCART_USER_ID'], user_token: Setting['DESERTCART_USER_TOKEN'], store_id: nil, store_token: nil)
44
+
45
+ store = Desertcart::Marketplace::Store.new(ledger_id: '1')
46
+
47
+ resource = Desertcart::Marketplace::Authorization.new(store: store)
48
+
49
+ operation = Desertcart::Marketplace::Authorization::Operations::Create.new(client: client, resource: resource)
50
+ operation.perform
51
+
52
+ Setting['DESERTCART_AMAZON_US_TOKEN'] = operation.result.resource.token
53
+ Setting['DESERTCART_AMAZON_US_ID'] = operation.result.resource.store.ledger_id
54
+ ```
55
+
56
+ ### Verification
57
+
58
+ Verify its all good.
59
+ ```ruby
60
+ require 'desertcart'
61
+
62
+ client = Desertcart::Client.new(user_id: Setting['DESERTCART_USER_ID'], user_token: Setting['DESERTCART_USER_TOKEN'], store_id: Setting['DESERTCART_AMAZON_US_ID'], store_token: Setting['DESERTCART_AMAZON_US_TOKEN'])
63
+
64
+ resource = Desertcart::Marketplace::Store.new(ledger_id: 'current')
65
+
66
+ operation = Desertcart::Marketplace::Store::Operations::Find.new(client: client, resource: resource)
67
+ operation.perform
68
+
69
+ operation.result.resource.ledger_id
70
+ ```
71
+
72
+ ### Search
73
+
74
+ To get list of items/search, you need to use Searcher class.
75
+ ```ruby
76
+ require 'desertcart'
77
+
78
+ client = Desertcart::Client.new(user_id: Setting['DESERTCART_USER_ID'], user_token: Setting['DESERTCART_USER_TOKEN'], store_id: Setting['DESERTCART_AMAZON_US_ID'], store_token: Setting['DESERTCART_AMAZON_US_TOKEN'])
79
+
80
+ search = Desertcart::Marketplace::OrderItem::Searcher.new(client: client, query: {})
81
+ search.resources
82
+ ```
83
+
84
+ Pending order items search with hash param.
85
+ ```ruby
86
+ require 'desertcart'
87
+
88
+ client = Desertcart::Client.new(user_id: Setting['DESERTCART_USER_ID'], user_token: Setting['DESERTCART_USER_TOKEN'], store_id: Setting['DESERTCART_AMAZON_US_ID'], store_token: Setting['DESERTCART_AMAZON_US_TOKEN'])
89
+
90
+ search = Desertcart::Marketplace::PendingOrderItem::Searcher.new(client: client, query: {updated_at_eq: Time.zone.now})
91
+ search.resources
92
+ ```
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
99
+
100
+ ## Contributing
101
+
102
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/desertcart.
103
+
104
+ ## License
105
+
106
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
107
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "desertcart"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require_relative 'lib/desertcart/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'desertcart'
7
+ # spec.version = Desertcart::VERSION
8
+ spec.version = '1.0.0'
9
+ spec.authors = ['Jozef Vaclavik']
10
+ spec.email = ['jozef@desertcart.com']
11
+
12
+ spec.summary = 'Communicate with Desertcart API'
13
+ spec.description = 'Client library to talk to Desertcart API. '\
14
+ 'Get products details, proceed with checkout '\
15
+ 'and retrieve informations about your orders.'
16
+ spec.homepage = 'https://developer.desertcart.com'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 3.0'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/desertcart/desertcart-ruby'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/desertcart/desertcart-ruby/blob/master/CHANGELOG.md'
23
+
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{\A(?:test|spec|features)/})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'ledger_sync', '~> 2.2.0'
34
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../user/deserializer'
4
+ require_relative '../marketplace/store/deserializer'
5
+
6
+ module Desertcart
7
+ class AuthenticationToken
8
+ class Deserializer < Desertcart::Deserializer
9
+ id
10
+ attribute :token
11
+ attribute :expires_at
12
+
13
+ references_one :user,
14
+ hash_attribute: 'user',
15
+ deserializer: Desertcart::User::Deserializer
16
+ references_one :store,
17
+ hash_attribute: 'store',
18
+ deserializer: Desertcart::Marketplace::Store::Deserializer
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class AuthenticationToken
5
+ module Operations
6
+ class Find < Desertcart::Operation::Find
7
+ class Contract < LedgerSync::Ledgers::Contract
8
+ params do
9
+ required(:external_id).maybe(:string)
10
+ required(:ledger_id).filled(:string)
11
+ optional(:token).maybe(:string)
12
+ optional(:expires_at).maybe(:string)
13
+ optional(:user).maybe(:hash, Types::Reference)
14
+ optional(:store).maybe(:hash, Types::Reference)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end