stigg-api-client 0.0.1.pre.b.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dbf4e72503b9416ddfd42d96f2aebea92370784f23f44c35bf252f64855cfcbe
4
+ data.tar.gz: 6737a488450aa135af6d4a7c850ba6582899b17e35bfd8264e81951d70ab4897
5
+ SHA512:
6
+ metadata.gz: 2c5448e553f8213254522c81fef16f85a94cd7e0e44c55b3a6acd0236ee7db647e49fdfe77828dc9c2489a1b265e251fdb1b944fae7fb8194ca69446fdd02b9d
7
+ data.tar.gz: 25ff5286ff877849553b09f909a5ed59a92b9f746ac05b745798d91175347087824c2e4cddd11808afe8f18be2d597953c14462d53653f1171bc85df1c4da900
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
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
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in stigg-api-client.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "bump", "~> 0.10"
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stigg-api-client (0.0.1.pre.b.1)
5
+ graphlient (~> 0.7.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (7.0.4.3)
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
+ bump (0.10.0)
17
+ concurrent-ruby (1.2.2)
18
+ diff-lcs (1.5.0)
19
+ faraday (2.7.4)
20
+ faraday-net_http (>= 2.0, < 3.1)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-net_http (3.0.2)
23
+ graphlient (0.7.0)
24
+ faraday (~> 2.0)
25
+ graphql-client
26
+ graphql (2.0.20)
27
+ graphql-client (0.18.0)
28
+ activesupport (>= 3.0)
29
+ graphql
30
+ i18n (1.12.0)
31
+ concurrent-ruby (~> 1.0)
32
+ json (2.6.2)
33
+ minitest (5.18.0)
34
+ parallel (1.22.1)
35
+ parser (3.1.2.1)
36
+ ast (~> 2.4.1)
37
+ rainbow (3.1.1)
38
+ rake (13.0.6)
39
+ regexp_parser (2.6.0)
40
+ rexml (3.2.5)
41
+ rspec (3.12.0)
42
+ rspec-core (~> 3.12.0)
43
+ rspec-expectations (~> 3.12.0)
44
+ rspec-mocks (~> 3.12.0)
45
+ rspec-core (3.12.0)
46
+ rspec-support (~> 3.12.0)
47
+ rspec-expectations (3.12.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.12.0)
50
+ rspec-mocks (3.12.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.12.0)
53
+ rspec-support (3.12.0)
54
+ rubocop (1.38.0)
55
+ json (~> 2.3)
56
+ parallel (~> 1.10)
57
+ parser (>= 3.1.2.1)
58
+ rainbow (>= 2.2.2, < 4.0)
59
+ regexp_parser (>= 1.8, < 3.0)
60
+ rexml (>= 3.2.5, < 4.0)
61
+ rubocop-ast (>= 1.23.0, < 2.0)
62
+ ruby-progressbar (~> 1.7)
63
+ unicode-display_width (>= 1.4.0, < 3.0)
64
+ rubocop-ast (1.23.0)
65
+ parser (>= 3.1.1.0)
66
+ ruby-progressbar (1.11.0)
67
+ ruby2_keywords (0.0.5)
68
+ tzinfo (2.0.6)
69
+ concurrent-ruby (~> 1.0)
70
+ unicode-display_width (2.3.0)
71
+
72
+ PLATFORMS
73
+ arm64-darwin-22
74
+ x86_64-darwin-21
75
+ x86_64-linux
76
+
77
+ DEPENDENCIES
78
+ bump (~> 0.10)
79
+ rake (~> 13.0)
80
+ rspec (~> 3.0)
81
+ rubocop (~> 1.21)
82
+ stigg-api-client!
83
+
84
+ BUNDLED WITH
85
+ 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,106 @@
1
+ # Stigg::Client
2
+
3
+ This Ruby gem provides a wrapper to [Stigg's GraphQL API](https://docs.stigg.io/docs/graphql-api) based on the operations that are in use by the [Stigg's Node.js SDK](https://docs.stigg.io/docs/nodejs-sdk).
4
+ It leverages the [graphlient](https://github.com/ashkan18/graphlient) library under the hood, and utilizes the `Graphlient::Client` class to execute the API requests.
5
+
6
+ ## Documentation
7
+
8
+ See https://docs.stigg.io/docs/ruby-sdk
9
+
10
+ ## Installation
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add stigg-api-client
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install stigg-api-client
19
+
20
+ ## Usage
21
+
22
+
23
+ Initialize the client:
24
+
25
+ ```ruby
26
+
27
+ require("stigg")
28
+
29
+ api_key = ENV["STIGG_SERVER_API_KEY"]
30
+
31
+ client = Stigg.create_client(api_key)
32
+
33
+ ```
34
+
35
+ Provision a customer
36
+
37
+ ```ruby
38
+
39
+ require("stigg")
40
+
41
+ api_key = ENV["STIGG_SERVER_API_KEY"]
42
+
43
+ client = Stigg.create_client(api_key)
44
+
45
+ resp = client.request(Stigg::Mutation::ProvisionCustomer, {
46
+ "input": {
47
+ "refId": "customer-id",
48
+ "name": "Acme",
49
+ "email": "hello@acme.com",
50
+ "couponRefId": "coupon-id",
51
+ "billingInformation": {
52
+ "language": "en",
53
+ "timezone": "America/New_York",
54
+ "billingAddress": {
55
+ "country": "US",
56
+ "city": "New York",
57
+ "state": "NY",
58
+ "addressLine1": "123 Main Street",
59
+ "addressLine2": "Apt. 1",
60
+ "phoneNumber": "+1 212-499-5321",
61
+ "postalCode": "10164"
62
+ },
63
+ "shippingAddress": {
64
+ "country": "US",
65
+ "city": "New York",
66
+ "state": "NY",
67
+ "addressLine1": "123 Main Street",
68
+ "addressLine2": "Apt. 1",
69
+ "phoneNumber": "+1 212-499-5321",
70
+ "postalCode": "10164"
71
+ }
72
+ },
73
+ "additionalMetaData": {
74
+ "key": "value"
75
+ },
76
+ "subscriptionParams": {
77
+ "planId": "plan-revvenu-basic"
78
+ }
79
+ }
80
+ })
81
+
82
+ p resp.data.provision_customer.customer.name
83
+
84
+ ```
85
+
86
+ Get a customer by ID
87
+
88
+ ```ruby
89
+
90
+
91
+ require("stigg")
92
+
93
+ api_key = ENV["STIGG_SERVER_API_KEY"]
94
+
95
+ client = Stigg.create_client(api_key)
96
+
97
+ resp = client.request(Stigg::Query::GetCustomerById, { 'customerId': 'customer-id' })
98
+ customer_edge = resp.data.customers.edges[0]
99
+ if customer_edge
100
+ customer = customer_edge.node
101
+ p customer.name
102
+ else
103
+ p 'Customer not found'
104
+ end
105
+
106
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
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
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,39 @@
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
+ schema_path = File.join(__dir__, 'generated/schema.json').to_s
23
+
24
+ client = Graphlient::Client.new(
25
+ api_url,
26
+ headers: {
27
+ "X-API-KEY": api_key
28
+ },
29
+ http_options: {
30
+ read_timeout: request_timeout,
31
+ write_timeout: request_timeout
32
+ },
33
+ schema_path: schema_path
34
+ )
35
+
36
+ Client.new(client)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Stigg
4
+ VERSION = "0.0.1-b.1"
5
+ end
data/lib/stigg.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "stigg/generated/operations"
4
+ require "stigg/version"
5
+ require "stigg/client"
data/project.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
3
+ "sourceRoot": "packages/api-client-ruby/lib",
4
+ "projectType": "library",
5
+ "implicitDependencies": ["api-client-schema"],
6
+ "targets": {
7
+ "generate": {
8
+ "executor": "@nrwl/workspace:run-commands",
9
+ "options": {
10
+ "command": "./scripts/generate.sh",
11
+ "cwd": "packages/api-client-ruby"
12
+ }
13
+ },
14
+ "publish": {
15
+ "executor": "@nrwl/workspace:run-commands",
16
+ "options": {
17
+ "command": "./scripts/publish.sh {args.ver}",
18
+ "cwd": "packages/api-client-ruby"
19
+ }
20
+ },
21
+ "test": {
22
+ "executor": "@nrwl/workspace:run-commands",
23
+ "options": {
24
+ "command": "rake spec",
25
+ "cwd": "packages/api-client-ruby"
26
+ },
27
+ "dependsOn": [
28
+ {
29
+ "projects": "self",
30
+ "target": "generate"
31
+ }
32
+ ]
33
+ }
34
+ },
35
+ "tags": []
36
+ }
@@ -0,0 +1,99 @@
1
+ import * as gql from 'graphql';
2
+ import fs from 'fs';
3
+
4
+ const schema = fs.readFileSync(
5
+ '../api-client-schema/src/generated/schema.graphql',
6
+ 'utf8'
7
+ );
8
+
9
+ const operations = fs.readFileSync('operations.graphql', 'utf8');
10
+
11
+ const gqlSchema = gql.buildSchema(schema);
12
+
13
+ const gqlOperations = gql.parse(operations);
14
+
15
+ function generateOperationsModule() {
16
+ const typeInfo = new gql.TypeInfo(gqlSchema);
17
+ const outputProgram = gql.visit(
18
+ gqlOperations,
19
+ gql.visitWithTypeInfo(typeInfo, visitor(gqlSchema, typeInfo))
20
+ );
21
+
22
+ const modules = ['Fragment', 'Mutation', 'Query']
23
+ .map(
24
+ (moduleName) =>
25
+ `module ${moduleName}\n${outputProgram
26
+ .filter((x) => x.moduleName === moduleName)
27
+ .map((x) => x.element)
28
+ .join('\n\n')}\nend`
29
+ )
30
+ .join('\n');
31
+
32
+ return `# frozen_string_literal: true\n\nmodule Stigg\n${modules}\nend`;
33
+ }
34
+
35
+ function findFragments(node, results = new Set()) {
36
+ if (node.kind === 'FragmentSpread') {
37
+ results.add(node.name.value);
38
+ gqlOperations.definitions.find((def) => {
39
+ if (
40
+ def.kind === 'FragmentDefinition' &&
41
+ def.name.value === node.name.value
42
+ ) {
43
+ findFragments(def, results);
44
+ }
45
+ });
46
+ }
47
+ node.selectionSet?.selections?.forEach((node) =>
48
+ findFragments(node, results)
49
+ );
50
+ return results;
51
+ }
52
+
53
+ function visitor(schema, typeInfo) {
54
+ return {
55
+ enter(node) {
56
+ typeInfo.enter(node);
57
+ },
58
+ leave(node) {
59
+ typeInfo.leave(node);
60
+ switch (node.kind) {
61
+ case 'Document':
62
+ return node.definitions;
63
+ case 'OperationDefinition': {
64
+ const results = findFragments(node);
65
+ const rawQuery = node.loc.source.body.substring(
66
+ node.loc.start,
67
+ node.loc.end
68
+ );
69
+ const namelessQuery = rawQuery.replace(
70
+ `${node.operation} ${node.name.value}`,
71
+ `${node.operation} `
72
+ );
73
+ const includedFragments = [...results]
74
+ .map((x) => `#{Fragment::${x}}\n`)
75
+ .join('');
76
+ const constantName =
77
+ node.name.value[0].toUpperCase() + node.name.value.slice(1);
78
+ return {
79
+ moduleName: node.operation === 'mutation' ? 'Mutation' : 'Query',
80
+ element: `${constantName} = <<-GRAPHQL\n${namelessQuery}\n${includedFragments}GRAPHQL`,
81
+ };
82
+ }
83
+ case 'FragmentDefinition': {
84
+ const querySource = node.loc.source.body.substring(
85
+ node.loc.start,
86
+ node.loc.end
87
+ );
88
+ return {
89
+ moduleName: 'Fragment',
90
+ element: `${node.name.value} = <<-GRAPHQL\n${querySource}\nGRAPHQL`,
91
+ };
92
+ }
93
+ }
94
+ },
95
+ };
96
+ }
97
+
98
+ const module = generateOperationsModule();
99
+ fs.writeFileSync('lib/stigg/generated/operations.rb', module);
@@ -0,0 +1,17 @@
1
+ #!/bin/bash -e
2
+
3
+ # stitch the operation files together
4
+ cat ../api-client-schema/src/operations/*.graphql > operations.graphql
5
+
6
+ mkdir -p lib/stigg/generated/
7
+
8
+ cat <<-EOF > lib/stigg/generated/schema.json
9
+ $(echo { \"data\": ) $(cat ../api-client-schema/src/generated/schema.json) $(echo })
10
+ EOF
11
+
12
+ node scripts/generate-operations.mjs
13
+ rm operations.graphql
14
+
15
+ bundle exec rubocop -a lib/stigg/generated/operations.rb
16
+
17
+ printf "api-client-ruby generated!\n"
@@ -0,0 +1,28 @@
1
+ #!/bin/bash -e
2
+
3
+ VERSION=$1
4
+
5
+ if [ -z "$VERSION" ]; then
6
+ echo "Usage: ./scripts/publish.sh <version>"
7
+ exit 1
8
+ fi
9
+
10
+ bundle config unset deployment
11
+
12
+ bundle exec bump set "${VERSION}" --no-commit --no-bundle
13
+ git diff
14
+
15
+ echo "Building..."
16
+ bundle exec rake build
17
+
18
+ # create a temporary commit, since it's not possible to
19
+ # release with a dirty working directory
20
+ echo "Releasing..."
21
+ git tag -d "v#${VERSION}" || true
22
+ git add .
23
+ git commit --no-verify -m "tmp commit for ruby release"
24
+ git tag -a "v#${VERSION}" -m 'tmp tag'
25
+ bundle exec rake release -v || (git reset --soft HEAD~1 && exit 1)
26
+ git reset --soft HEAD~1
27
+
28
+ printf "api-client-ruby published!\n"
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/stigg/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "stigg-api-client"
7
+ spec.version = Stigg::VERSION
8
+ spec.authors = ["Stigg"]
9
+ spec.email = ["support@stigg.io"]
10
+
11
+ spec.summary = "Stigg API Client"
12
+ spec.description = "Stigg API Client for Ruby"
13
+ spec.homepage = "https://stigg.io"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.0.0"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(__dir__) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
23
+ end
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "graphlient", "~> 0.7.0"
30
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stigg-api-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.b.1
5
+ platform: ruby
6
+ authors:
7
+ - Stigg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-05-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: graphlient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.0
27
+ description: Stigg API Client for Ruby
28
+ email:
29
+ - support@stigg.io
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/stigg.rb
42
+ - lib/stigg/client.rb
43
+ - lib/stigg/version.rb
44
+ - project.json
45
+ - scripts/generate-operations.mjs
46
+ - scripts/generate.sh
47
+ - scripts/publish.sh
48
+ - stigg-api-client.gemspec
49
+ homepage: https://stigg.io
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://stigg.io
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.0.0
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">"
66
+ - !ruby/object:Gem::Version
67
+ version: 1.3.1
68
+ requirements: []
69
+ rubygems_version: 3.4.10
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Stigg API Client
73
+ test_files: []