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
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class Authorization < Desertcart::Resource
6
+ references_one :store, to: Desertcart::Marketplace::Store
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'order_item'
4
+
5
+ module Desertcart
6
+ module Marketplace
7
+ class Movement < Desertcart::Resource
8
+ attribute :carrier, type: LedgerSync::Type::String
9
+ attribute :tracking_number, type: LedgerSync::Type::String
10
+ attribute :shipping_address_id, type: LedgerSync::Type::Integer
11
+ attribute :departed_at, type: LedgerSync::Type::Integer
12
+ attribute :estimated_arrival_at, type: LedgerSync::Type::Integer
13
+ references_many :order_items, to: Desertcart::Marketplace::OrderItem
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'shipping_address'
4
+
5
+ module Desertcart
6
+ module Marketplace
7
+ class OrderItem < Desertcart::Resource
8
+ attribute :name, type: LedgerSync::Type::String
9
+ attribute :store_uid, type: LedgerSync::Type::String
10
+ attribute :store_id, type: LedgerSync::Type::Integer
11
+ attribute :order_reference, type: LedgerSync::Type::String
12
+ attribute :offer_reference, type: LedgerSync::Type::String
13
+ attribute :merchant_id, type: LedgerSync::Type::String
14
+ attribute :currency_code, type: LedgerSync::Type::String
15
+ attribute :price, type: LedgerSync::Type::Integer
16
+ attribute :title, type: LedgerSync::Type::String
17
+ attribute :state, type: LedgerSync::Type::String
18
+ attribute :marketplace_shipping_state, type: LedgerSync::Type::String
19
+ attribute :reason_for_rejection, type: LedgerSync::Type::String
20
+ attribute :checkin_condition, type: LedgerSync::Type::String
21
+ attribute :shipment_movement_id, type: LedgerSync::Type::Integer
22
+ attribute :seller_reference_number, type: LedgerSync::Type::String
23
+ attribute :seller_notes, type: LedgerSync::Type::String
24
+ attribute :order_placed_at, type: LedgerSync::Type::Integer
25
+ attribute :acceptance_expiration_at, type: LedgerSync::Type::Integer
26
+ attribute :estimated_delivery_date, type: LedgerSync::Type::String
27
+ attribute :accepted_at, type: LedgerSync::Type::Integer
28
+ attribute :purchase_order, type: LedgerSync::Type::String
29
+ attribute :note, type: LedgerSync::Type::String
30
+ references_one :shipping_address,
31
+ to: Desertcart::Marketplace::ShippingAddress
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class OrderItemAcceptance < Desertcart::Resource
6
+ references_one :order_item, to: Desertcart::Marketplace::OrderItem
7
+ attribute :seller_reference_number, type: LedgerSync::Type::String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class OrderItemRejection < Desertcart::Resource
6
+ references_one :order_item, to: Desertcart::Marketplace::OrderItem
7
+ attribute :reason, type: LedgerSync::Type::String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class Registration < Desertcart::Resource
6
+ attribute :name, type: LedgerSync::Type::String
7
+ attribute :url, type: LedgerSync::Type::String
8
+ attribute :country_code, type: LedgerSync::Type::String
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class ShippingAddress < Desertcart::Resource
6
+ attribute :name, type: LedgerSync::Type::String
7
+ attribute 'address_line_1', type: LedgerSync::Type::String
8
+ attribute 'address_line_2', type: LedgerSync::Type::String
9
+ attribute :city, type: LedgerSync::Type::String
10
+ attribute :state, type: LedgerSync::Type::String
11
+ attribute :zip_code, type: LedgerSync::Type::String
12
+ attribute :country, type: LedgerSync::Type::String
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ module Marketplace
5
+ class Store < Desertcart::Resource
6
+ attribute :name, type: LedgerSync::Type::String
7
+ attribute :url, type: LedgerSync::Type::String
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class Session < Desertcart::Resource
5
+ attribute :login, type: LedgerSync::Type::String
6
+ attribute :password, type: LedgerSync::Type::String
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class User < Desertcart::Resource
5
+ attribute :email, type: LedgerSync::Type::String
6
+ end
7
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class Searcher < LedgerSync::Ledgers::Searcher
5
+ def resources
6
+ case response.status
7
+ when 200
8
+ response.body
9
+ .fetch(ledger_resource_type.pluralize)
10
+ .map { |o| deserialized_resource(hash: o) }
11
+ else
12
+ []
13
+ end
14
+ end
15
+
16
+ def next?
17
+ case response.status
18
+ when 200
19
+ response.body.dig('meta', 'pagination', 'next_page')
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+ def deserialized_resource(hash:)
26
+ searcher_deserializer.deserialize(
27
+ hash: hash,
28
+ resource: resource_class.new
29
+ )
30
+ end
31
+
32
+ def response
33
+ @response ||= client.read(
34
+ path: ledger_resources_path,
35
+ params: query
36
+ )
37
+ end
38
+
39
+ def resource_class
40
+ @resource_class ||= self.class.inferred_resource_class
41
+ end
42
+
43
+ def searcher_deserializer_class
44
+ @searcher_deserializer_class ||= self.class.inferred_serialization_class(
45
+ type: 'SearcherDeserializer'
46
+ )
47
+ end
48
+
49
+ def searcher_deserializer
50
+ searcher_deserializer_class.new
51
+ end
52
+
53
+ def ledger_namespace_path
54
+ @ledger_namespace_path ||= nil
55
+ end
56
+
57
+ def ledger_resources_path
58
+ @ledger_resources_path ||= [
59
+ ledger_namespace_path,
60
+ ledger_resource_type.pluralize
61
+ ].compact.join('/')
62
+ end
63
+
64
+ def ledger_resource_type
65
+ @ledger_resource_type ||= client.class.ledger_resource_type_for(
66
+ resource_class: resource_class
67
+ )
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class Serializer < LedgerSync::Serializer
5
+ def self.id
6
+ attribute('id', resource_attribute: :ledger_id)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../resources/authentication_token'
4
+
5
+ module Desertcart
6
+ class Session
7
+ module Operations
8
+ class Create < Desertcart::Operation::Create
9
+ class Contract < LedgerSync::Ledgers::Contract
10
+ params do
11
+ required(:external_id).maybe(:string)
12
+ required(:ledger_id).filled(:string)
13
+ required(:login).filled(:string)
14
+ required(:password).filled(:string)
15
+ end
16
+ end
17
+
18
+ def deserialized_resource
19
+ Desertcart::AuthenticationToken::Deserializer.new.deserialize(
20
+ hash: response.body['authentication_token'],
21
+ resource: Desertcart::AuthenticationToken.new
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../resources/authentication_token'
4
+
5
+ module Desertcart
6
+ class Session
7
+ module Operations
8
+ class Find < Desertcart::Operation::Find
9
+ class Contract < LedgerSync::Ledgers::Contract
10
+ params do
11
+ required(:external_id).maybe(:string)
12
+ required(:ledger_id).filled(:string)
13
+ optional(:login).maybe(:string)
14
+ optional(:password).maybe(:string)
15
+ end
16
+ end
17
+
18
+ def deserialized_resource
19
+ Desertcart::AuthenticationToken::Deserializer.new.deserialize(
20
+ hash: response.body['authentication_token'],
21
+ resource: Desertcart::AuthenticationToken.new
22
+ )
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class Session
5
+ class Serializer < Desertcart::Serializer
6
+ attribute :login
7
+ attribute :password
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class User
5
+ class Deserializer < Desertcart::Deserializer
6
+ id
7
+ attribute :email
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ class User
5
+ class Serializer < Desertcart::Serializer
6
+ id
7
+ attribute :email
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Desertcart
4
+ VERSION = '1.0.0'
5
+ end
data/lib/desertcart.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'desertcart/config'
4
+ require 'desertcart/version'
5
+
6
+ module Desertcart
7
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: desertcart
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jozef Vaclavik
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ledger_sync
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.2.0
27
+ description: Client library to talk to Desertcart API. Get products details, proceed
28
+ with checkout and retrieve informations about your orders.
29
+ email:
30
+ - jozef@desertcart.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/workflows/main.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - CHANGELOG.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE.txt
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - desertcart.gemspec
47
+ - lib/desertcart.rb
48
+ - lib/desertcart/authentication_token/deserializer.rb
49
+ - lib/desertcart/authentication_token/operations/find.rb
50
+ - lib/desertcart/authentication_token/serializer.rb
51
+ - lib/desertcart/client.rb
52
+ - lib/desertcart/config.rb
53
+ - lib/desertcart/deserializer.rb
54
+ - lib/desertcart/marketplace/authorizations/operations/create.rb
55
+ - lib/desertcart/marketplace/authorizations/serializer.rb
56
+ - lib/desertcart/marketplace/movement/deserializer.rb
57
+ - lib/desertcart/marketplace/movement/operations/create.rb
58
+ - lib/desertcart/marketplace/movement/serializer.rb
59
+ - lib/desertcart/marketplace/order_item/deserializer.rb
60
+ - lib/desertcart/marketplace/order_item/operations/find.rb
61
+ - lib/desertcart/marketplace/order_item/operations/update.rb
62
+ - lib/desertcart/marketplace/order_item/searcher.rb
63
+ - lib/desertcart/marketplace/order_item/serializer.rb
64
+ - lib/desertcart/marketplace/order_item_acceptance/operations/create.rb
65
+ - lib/desertcart/marketplace/order_item_acceptance/serializer.rb
66
+ - lib/desertcart/marketplace/order_item_rejection/operations/create.rb
67
+ - lib/desertcart/marketplace/order_item_rejection/serializer.rb
68
+ - lib/desertcart/marketplace/pending_order_items/searcher.rb
69
+ - lib/desertcart/marketplace/registration/operations/create.rb
70
+ - lib/desertcart/marketplace/registration/serializer.rb
71
+ - lib/desertcart/marketplace/shipping_address/deserializer.rb
72
+ - lib/desertcart/marketplace/store/deserializer.rb
73
+ - lib/desertcart/marketplace/store/operations/find.rb
74
+ - lib/desertcart/marketplace/store/serializer.rb
75
+ - lib/desertcart/operation.rb
76
+ - lib/desertcart/operation/create.rb
77
+ - lib/desertcart/operation/find.rb
78
+ - lib/desertcart/operation/update.rb
79
+ - lib/desertcart/resource.rb
80
+ - lib/desertcart/resources/authentication_token.rb
81
+ - lib/desertcart/resources/marketplace/authorization.rb
82
+ - lib/desertcart/resources/marketplace/movement.rb
83
+ - lib/desertcart/resources/marketplace/order_item.rb
84
+ - lib/desertcart/resources/marketplace/order_item_acceptance.rb
85
+ - lib/desertcart/resources/marketplace/order_item_rejection.rb
86
+ - lib/desertcart/resources/marketplace/registration.rb
87
+ - lib/desertcart/resources/marketplace/shipping_address.rb
88
+ - lib/desertcart/resources/marketplace/store.rb
89
+ - lib/desertcart/resources/session.rb
90
+ - lib/desertcart/resources/user.rb
91
+ - lib/desertcart/searcher.rb
92
+ - lib/desertcart/serializer.rb
93
+ - lib/desertcart/session/operations/create.rb
94
+ - lib/desertcart/session/operations/find.rb
95
+ - lib/desertcart/session/serializer.rb
96
+ - lib/desertcart/user/deserializer.rb
97
+ - lib/desertcart/user/serializer.rb
98
+ - lib/desertcart/version.rb
99
+ homepage: https://developer.desertcart.com
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ homepage_uri: https://developer.desertcart.com
104
+ source_code_uri: https://github.com/desertcart/desertcart-ruby
105
+ changelog_uri: https://github.com/desertcart/desertcart-ruby/blob/master/CHANGELOG.md
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '3.0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubygems_version: 3.2.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Communicate with Desertcart API
125
+ test_files: []