dipps-client 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 030611f374109f4a252e81751aa420d1db645face15b56a9a410453630df70e4
4
+ data.tar.gz: 25b49de4b84b41b10600c07c00396980cd619c0ce1e9cfc7a4b3204413ccbb48
5
+ SHA512:
6
+ metadata.gz: de90cf81eb26fc30df999bd8cd29956e8dce1fe850099b31d6d43694dd88a76cf0e9aceb70b750fefc51c90fc796013482173826eb8f820c531bc8e798303015
7
+ data.tar.gz: 253044b488281b9422fc57057401599efe44dc81f7b5d5fbce4324b2b431594edb75ffa561a00a7502384e62c484b85f23f6a67508469e0c5edb5e23a02f029a
data/.gitignore ADDED
@@ -0,0 +1,13 @@
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
12
+
13
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 13.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'pry'
data/Gemfile.lock ADDED
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dipps-client (0.2.0)
5
+ activesupport (>= 4.0)
6
+ graphql-client (~> 0.17.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.4.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ coderay (1.1.3)
18
+ concurrent-ruby (1.1.9)
19
+ diff-lcs (1.4.4)
20
+ graphql (1.12.16)
21
+ graphql-client (0.17.0)
22
+ activesupport (>= 3.0)
23
+ graphql (~> 1.10)
24
+ i18n (1.8.10)
25
+ concurrent-ruby (~> 1.0)
26
+ method_source (1.0.0)
27
+ minitest (5.14.4)
28
+ pry (0.14.1)
29
+ coderay (~> 1.1)
30
+ method_source (~> 1.0)
31
+ rake (13.0.6)
32
+ rspec (3.10.0)
33
+ rspec-core (~> 3.10.0)
34
+ rspec-expectations (~> 3.10.0)
35
+ rspec-mocks (~> 3.10.0)
36
+ rspec-core (3.10.1)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-expectations (3.10.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-mocks (3.10.2)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.10.0)
44
+ rspec-support (3.10.2)
45
+ tzinfo (2.0.4)
46
+ concurrent-ruby (~> 1.0)
47
+ zeitwerk (2.4.2)
48
+
49
+ PLATFORMS
50
+ x86_64-darwin-20
51
+
52
+ DEPENDENCIES
53
+ dipps-client!
54
+ pry
55
+ rake (~> 13.0)
56
+ rspec (~> 3.0)
57
+
58
+ BUNDLED WITH
59
+ 2.2.15
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Dipps::Client
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dipps/client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dipps-client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dipps-client
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dipps-client.
data/Rakefile ADDED
@@ -0,0 +1,20 @@
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
9
+
10
+ task :dump_schema do
11
+ require 'dipps/client'
12
+
13
+ Dipps::Client.configure do |config|
14
+ config.api_url = ENV['DIPPS_API_URL']
15
+ config.api_key = ENV['DIPPS_API_KEY']
16
+ config.fetch_schema = true
17
+ end
18
+
19
+ File.write(Dipps::Client::SCHEMA_PATH, Dipps::Client::Schema.to_json)
20
+ end
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 "dipps/client"
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,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/dipps/client/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "dipps-client"
7
+ spec.version = Dipps::Client::VERSION
8
+ spec.authors = ["Roman Kuznietsov"]
9
+ spec.email = ["roman@kuznietsov.net"]
10
+ spec.license = "MIT"
11
+
12
+ spec.summary = "Dipps Partner API Client"
13
+ spec.homepage = "https://github.com/Skiwo/dipps-client"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/Skiwo/dipps-client"
20
+ spec.metadata["changelog_uri"] = "https://github.com/Skiwo/dipps-client"
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
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 'graphql-client', '~> 0.17.0'
30
+ spec.add_dependency 'activesupport', '>= 4.0'
31
+ end
@@ -0,0 +1,21 @@
1
+ module Dipps
2
+ module Client
3
+ class Configuration
4
+ OPTIONS = %i[api_key api_url fetch_schema]
5
+
6
+ def initialize
7
+ @options = {}
8
+ end
9
+
10
+ OPTIONS.each do |option|
11
+ define_method(option) do
12
+ @options[option]
13
+ end
14
+
15
+ define_method("#{option}=") do |value|
16
+ @options[option] = value
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'schema'
2
+
3
+ module Dipps
4
+ module Client
5
+ GraphqlClient = GraphQL::Client.new(schema: Schema, execute: Transport)
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ module Dipps
2
+ module Client
3
+ module Queries
4
+ Clients = GraphqlClient.parse <<~GQL
5
+ query {
6
+ clients {
7
+ id
8
+ clientType
9
+ clientNumber
10
+ email
11
+ name
12
+ friendlyName
13
+ orgNumber
14
+ phone
15
+ address {
16
+ line1
17
+ line2
18
+ postalCode
19
+ city
20
+ county
21
+ country
22
+ latitude
23
+ longitude
24
+ }
25
+ referencePeople {
26
+ name
27
+ email
28
+ phone
29
+ referenceNumber
30
+ }
31
+ archivedAt
32
+ }
33
+ }
34
+ GQL
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,47 @@
1
+ module Dipps
2
+ module Client
3
+ module Queries
4
+ CreateClient = GraphqlClient.parse <<~GQL
5
+ mutation($attributes: CreateClientAttributes!) {
6
+ createClient(
7
+ input: {
8
+ attributes: $attributes
9
+ }
10
+ ) {
11
+ client {
12
+ id
13
+ clientType
14
+ clientNumber
15
+ email
16
+ name
17
+ friendlyName
18
+ orgNumber
19
+ phone
20
+ address {
21
+ line1
22
+ line2
23
+ postalCode
24
+ city
25
+ county
26
+ country
27
+ latitude
28
+ longitude
29
+ }
30
+ referencePeople {
31
+ name
32
+ email
33
+ phone
34
+ referenceNumber
35
+ }
36
+ archivedAt
37
+ }
38
+ errors {
39
+ code
40
+ path
41
+ }
42
+ }
43
+ }
44
+ GQL
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,31 @@
1
+ module Dipps
2
+ module Client
3
+ module Queries
4
+ CreateOwnInvoice = GraphqlClient.parse <<~GQL
5
+ mutation($freelance_profile_id: ID!, $attributes: InvoiceAttributes!) {
6
+ createOwnInvoice(
7
+ input: {
8
+ freelanceProfileId: $freelance_profile_id,
9
+ attributes: $attributes
10
+ }
11
+ ) {
12
+ invoice {
13
+ id
14
+ lines {
15
+ workInvoiceLineId
16
+ workStartedAt
17
+ workEndedAt
18
+ vatRate
19
+ lineType
20
+ }
21
+ }
22
+ errors {
23
+ code
24
+ path
25
+ }
26
+ }
27
+ }
28
+ GQL
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,48 @@
1
+ module Dipps
2
+ module Client
3
+ module Queries
4
+ UpdateClient = GraphqlClient.parse <<~GQL
5
+ mutation($id: ID!, $attributes: UpdateClientAttributes!) {
6
+ updateClient(
7
+ input: {
8
+ id: $id,
9
+ attributes: $attributes
10
+ }
11
+ ) {
12
+ client {
13
+ id
14
+ clientType
15
+ clientNumber
16
+ email
17
+ name
18
+ friendlyName
19
+ orgNumber
20
+ phone
21
+ address {
22
+ line1
23
+ line2
24
+ postalCode
25
+ city
26
+ county
27
+ country
28
+ latitude
29
+ longitude
30
+ }
31
+ referencePeople {
32
+ name
33
+ email
34
+ phone
35
+ referenceNumber
36
+ }
37
+ archivedAt
38
+ }
39
+ errors {
40
+ code
41
+ path
42
+ }
43
+ }
44
+ }
45
+ GQL
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,13 @@
1
+ require_relative 'graphql_client'
2
+
3
+ require_relative 'queries/create_own_invoice'
4
+ require_relative 'queries/clients'
5
+ require_relative 'queries/create_client'
6
+ require_relative 'queries/update_client'
7
+
8
+ module Dipps
9
+ module Client
10
+ module Queries
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'transport'
2
+
3
+ module Dipps
4
+ module Client
5
+ if configuration.fetch_schema
6
+ Schema = GraphQL::Client.load_schema(Transport)
7
+ else
8
+ Schema = GraphQL::Client.load_schema(SCHEMA_PATH)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ require 'graphql/client'
2
+ require 'graphql/client/http'
3
+
4
+ module Dipps
5
+ module Client
6
+ Transport = GraphQL::Client::HTTP.new(Dipps::Client.configuration.api_url) do
7
+ def headers(_)
8
+ { 'Authorization' => "Bearer #{Dipps::Client.configuration.api_key}" }
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dipps
4
+ module Client
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'client/version'
4
+ require_relative 'client/configuration'
5
+
6
+ module Dipps
7
+ module Client
8
+ SCHEMA_PATH = File.expand_path(
9
+ File.join(File.dirname(__FILE__), '..', '..', 'vendor', 'schema.json')
10
+ ).freeze
11
+
12
+ class << self
13
+ def configure
14
+ yield(configuration)
15
+
16
+ unless require_relative 'client/queries'
17
+ raise 'Dipps::Client has already been configured.'
18
+ end
19
+ end
20
+
21
+ def configuration
22
+ @configuration ||= Dipps::Client::Configuration.new
23
+ end
24
+
25
+ def create_own_invoice(freelance_profile_id:, attributes:)
26
+ GraphqlClient.query(
27
+ Dipps::Client::Queries::CreateOwnInvoice,
28
+ variables: {
29
+ freelance_profile_id: freelance_profile_id,
30
+ attributes: attributes
31
+ }
32
+ ).data.to_h['createOwnInvoice']
33
+ end
34
+
35
+ def clients
36
+ GraphqlClient.query(
37
+ Dipps::Client::Queries::Clients
38
+ ).data.to_h['clients']
39
+ end
40
+
41
+ def create_client(attributes:)
42
+ GraphqlClient.query(
43
+ Dipps::Client::Queries::CreateClient,
44
+ variables: {
45
+ attributes: attributes
46
+ }
47
+ ).data.to_h['createClient']
48
+ end
49
+
50
+ def update_client(id:, attributes:)
51
+ GraphqlClient.query(
52
+ Dipps::Client::Queries::UpdateClient,
53
+ variables: {
54
+ id: id,
55
+ attributes: attributes
56
+ }
57
+ ).data.to_h['updateClient']
58
+ end
59
+ end
60
+ end
61
+ end