stigg-api-client 0.1.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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +81 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/Rakefile +12 -0
- data/lib/stigg/client.rb +37 -0
- data/lib/stigg/generated/operations.rb +608 -0
- data/lib/stigg/version.rb +5 -0
- data/lib/stigg.rb +5 -0
- data/package.json +4 -0
- data/project.json +3 -0
- data/schema.json +50719 -0
- data/scripts/generate-operations.mjs +99 -0
- data/scripts/generate.sh +14 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb5028b371f0211e5eb36b851f178f31511e4fab423638d92724e534d120a400
|
4
|
+
data.tar.gz: 31e5e37fab257d53fd006f5854ad3c8e4650398607a4c7113ba37901eef34df8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84fde9de567650ab41a0ee5f13f7322303dae573457dbe276082c77dce300b1444ab3d1e7f8f0f087dd5c790ffa1abca16ef349387603f3c80cced268882f994
|
7
|
+
data.tar.gz: 3dbab4968ff612a628dca33a59766b802d397d6a48d5a4ab8c06f2c809790eaf89383126380df2e8336d44dbfcee0c753a134a9eb96beb77b06d359ae1c877ea
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
Naming/ConstantName:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ModuleLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/MutableConstant:
|
22
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
stigg-api-client (0.1.0)
|
5
|
+
graphlient (~> 0.7.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (7.0.4)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
ast (2.4.2)
|
16
|
+
concurrent-ruby (1.1.10)
|
17
|
+
diff-lcs (1.5.0)
|
18
|
+
faraday (2.6.0)
|
19
|
+
faraday-net_http (>= 2.0, < 3.1)
|
20
|
+
ruby2_keywords (>= 0.0.4)
|
21
|
+
faraday-net_http (3.0.2)
|
22
|
+
graphlient (0.7.0)
|
23
|
+
faraday (~> 2.0)
|
24
|
+
graphql-client
|
25
|
+
graphql (2.0.15)
|
26
|
+
graphql-client (0.18.0)
|
27
|
+
activesupport (>= 3.0)
|
28
|
+
graphql
|
29
|
+
i18n (1.12.0)
|
30
|
+
concurrent-ruby (~> 1.0)
|
31
|
+
json (2.6.2)
|
32
|
+
minitest (5.16.3)
|
33
|
+
parallel (1.22.1)
|
34
|
+
parser (3.1.2.1)
|
35
|
+
ast (~> 2.4.1)
|
36
|
+
rainbow (3.1.1)
|
37
|
+
rake (13.0.6)
|
38
|
+
regexp_parser (2.6.0)
|
39
|
+
rexml (3.2.5)
|
40
|
+
rspec (3.12.0)
|
41
|
+
rspec-core (~> 3.12.0)
|
42
|
+
rspec-expectations (~> 3.12.0)
|
43
|
+
rspec-mocks (~> 3.12.0)
|
44
|
+
rspec-core (3.12.0)
|
45
|
+
rspec-support (~> 3.12.0)
|
46
|
+
rspec-expectations (3.12.0)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.12.0)
|
49
|
+
rspec-mocks (3.12.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.12.0)
|
52
|
+
rspec-support (3.12.0)
|
53
|
+
rubocop (1.38.0)
|
54
|
+
json (~> 2.3)
|
55
|
+
parallel (~> 1.10)
|
56
|
+
parser (>= 3.1.2.1)
|
57
|
+
rainbow (>= 2.2.2, < 4.0)
|
58
|
+
regexp_parser (>= 1.8, < 3.0)
|
59
|
+
rexml (>= 3.2.5, < 4.0)
|
60
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
61
|
+
ruby-progressbar (~> 1.7)
|
62
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
63
|
+
rubocop-ast (1.23.0)
|
64
|
+
parser (>= 3.1.1.0)
|
65
|
+
ruby-progressbar (1.11.0)
|
66
|
+
ruby2_keywords (0.0.5)
|
67
|
+
tzinfo (2.0.5)
|
68
|
+
concurrent-ruby (~> 1.0)
|
69
|
+
unicode-display_width (2.3.0)
|
70
|
+
|
71
|
+
PLATFORMS
|
72
|
+
x86_64-darwin-21
|
73
|
+
|
74
|
+
DEPENDENCIES
|
75
|
+
rake (~> 13.0)
|
76
|
+
rspec (~> 3.0)
|
77
|
+
rubocop (~> 1.21)
|
78
|
+
stigg-api-client!
|
79
|
+
|
80
|
+
BUNDLED WITH
|
81
|
+
2.3.25
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Anton Zagrebelny
|
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,109 @@
|
|
1
|
+
# Stigg::Client
|
2
|
+
|
3
|
+
This library provides a Ruby wrapper to [Stigg's GraphQL API](https://docs.stigg.io/docs/graphql-api) based on
|
4
|
+
the operations the [Stigg's Node.js SDK](https://docs.stigg.io/docs/nodejs-sdk) is using under the hood.
|
5
|
+
|
6
|
+
It leverages the [graphlient](https://github.com/ashkan18/graphlient) library, and utilizes the `Graphlient::Client` class to send the API requests.
|
7
|
+
|
8
|
+
|
9
|
+
## Documentation
|
10
|
+
|
11
|
+
See https://docs.stigg.io/docs/ruby-sdk
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Install the gem and add to the application's Gemfile by executing:
|
16
|
+
|
17
|
+
$ bundle add stigg-api-client
|
18
|
+
|
19
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
20
|
+
|
21
|
+
$ gem install stigg-api-client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
|
26
|
+
Initialize the client:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
|
30
|
+
require("stigg")
|
31
|
+
|
32
|
+
api_key = ENV["STIGG_SERVER_API_KEY"]
|
33
|
+
|
34
|
+
client = Stigg.create_client(api_key)
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
Provision a customer
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
|
42
|
+
require("stigg")
|
43
|
+
|
44
|
+
api_key = ENV["STIGG_SERVER_API_KEY"]
|
45
|
+
|
46
|
+
client = Stigg.create_client(api_key)
|
47
|
+
|
48
|
+
resp = client.request(Stigg::Mutation::ProvisionCustomer, {
|
49
|
+
"input": {
|
50
|
+
"refId": "customer-id",
|
51
|
+
"name": "Acme",
|
52
|
+
"email": "hello@acme.com",
|
53
|
+
"couponRefId": "coupon-id",
|
54
|
+
"billingInformation": {
|
55
|
+
"language": "en",
|
56
|
+
"timezone": "America/New_York",
|
57
|
+
"billingAddress": {
|
58
|
+
"country": "US",
|
59
|
+
"city": "New York",
|
60
|
+
"state": "NY",
|
61
|
+
"addressLine1": "123 Main Street",
|
62
|
+
"addressLine2": "Apt. 1",
|
63
|
+
"phoneNumber": "+1 212-499-5321",
|
64
|
+
"postalCode": "10164"
|
65
|
+
},
|
66
|
+
"shippingAddress": {
|
67
|
+
"country": "US",
|
68
|
+
"city": "New York",
|
69
|
+
"state": "NY",
|
70
|
+
"addressLine1": "123 Main Street",
|
71
|
+
"addressLine2": "Apt. 1",
|
72
|
+
"phoneNumber": "+1 212-499-5321",
|
73
|
+
"postalCode": "10164"
|
74
|
+
}
|
75
|
+
},
|
76
|
+
"additionalMetaData": {
|
77
|
+
"key": "value"
|
78
|
+
},
|
79
|
+
"subscriptionParams": {
|
80
|
+
"planId": "plan-revvenu-basic"
|
81
|
+
}
|
82
|
+
}
|
83
|
+
})
|
84
|
+
|
85
|
+
p resp.data.provision_customer.customer.name
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
Get a customer by ID
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
|
93
|
+
|
94
|
+
require("stigg")
|
95
|
+
|
96
|
+
api_key = ENV["STIGG_SERVER_API_KEY"]
|
97
|
+
|
98
|
+
client = Stigg.create_client(api_key)
|
99
|
+
|
100
|
+
resp = client.request(Stigg::Query::GetCustomerById, { 'customerId': 'customer-id' })
|
101
|
+
customer_edge = resp.data.customers.edges[0]
|
102
|
+
if customer_edge
|
103
|
+
customer = customer_edge.node
|
104
|
+
p customer.name
|
105
|
+
else
|
106
|
+
p 'Customer not found'
|
107
|
+
end
|
108
|
+
|
109
|
+
```
|
data/Rakefile
ADDED
data/lib/stigg/client.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "version"
|
4
|
+
require "graphlient"
|
5
|
+
|
6
|
+
module Stigg
|
7
|
+
class Client
|
8
|
+
def initialize(client)
|
9
|
+
@client = client
|
10
|
+
end
|
11
|
+
|
12
|
+
def request(query, variables = nil)
|
13
|
+
@client.query(query, variables)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# @param [String] api_key
|
19
|
+
# @param [String api_url
|
20
|
+
# @return [Client]
|
21
|
+
def create_client(api_key, api_url = "https://api.stigg.io/graphql", request_timeout=30)
|
22
|
+
client = Graphlient::Client.new(
|
23
|
+
api_url,
|
24
|
+
headers: {
|
25
|
+
"X-API-KEY": api_key
|
26
|
+
},
|
27
|
+
http_options: {
|
28
|
+
read_timeout: request_timeout,
|
29
|
+
write_timeout: request_timeout
|
30
|
+
},
|
31
|
+
schema_path: 'schema.json'
|
32
|
+
)
|
33
|
+
|
34
|
+
Client.new(client)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|