dipps-client 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d6f57bbadb064a385918339afd3d132c3a037b8cf875b0fe005c1fc3f8298fb
4
- data.tar.gz: d5dce5ea6e0b511be6aecf6c55d79d37fc644a1070faff4322abe259bbbbdc4c
3
+ metadata.gz: f55122ca9cde052f4927804ebab6419948025d45d1b1f3c6ad16c457968977a9
4
+ data.tar.gz: 0236e9bad74ea19f3906264f5bf62216e2aa9ca0b38cb84ffa551d28e7a33322
5
5
  SHA512:
6
- metadata.gz: 0e860c4dd776d0e20843e598a6ba46a1e5723860aff6e2884a5124aa674620201d8b9ed7b07e9bf3432052403a0ce40323924d39ccfff984459cddf7d1bd6f9e
7
- data.tar.gz: 53bb6b11a07090126ee0045f455ae08c7a2ba2a819417ac77c0e15f811eac1ca6800f976b76aad68e33755c2ad13492bc42da15f3bfbf535af05bdbc93ddf02a
6
+ metadata.gz: 8b40c5cd5a3272b91938360a36fd4eb26116b2b80966f0a33f236287999d162979af0e55eae7a8154bfb7734990edddcaa8df0ec5545c7fc632bd096d1185882
7
+ data.tar.gz: fea5eabf78ba9cb518a367c0112a8349bec52157e79d771c7f9710c90e1c3d4dcc18268f0ef9307081939bf1acec958ed4100ccfa8cd572abd9a13853ee8d9f9
@@ -0,0 +1,6 @@
1
+ module Dipps
2
+ module Client
3
+ class Error < StandardError
4
+ end
5
+ end
6
+ end
@@ -2,10 +2,11 @@ module Dipps
2
2
  module Client
3
3
  module Queries
4
4
  Clients = GraphqlClient.parse <<~GQL
5
- query($orgNumber: String, $email: String) {
5
+ query($orgNumber: String, $email: String, $freelance_profile_id: ID!) {
6
6
  clients(
7
7
  orgNumber: $orgNumber,
8
- email: $email
8
+ email: $email,
9
+ freelanceProfileId: $freelance_profile_id
9
10
  ) {
10
11
  id
11
12
  clientType
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dipps
4
4
  module Client
5
- VERSION = "0.3.0"
5
+ VERSION = "0.5.0"
6
6
  end
7
7
  end
data/lib/dipps/client.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'client/version'
4
4
  require_relative 'client/configuration'
5
+ require_relative 'client/error'
5
6
 
6
7
  module Dipps
7
8
  module Client
@@ -22,43 +23,58 @@ module Dipps
22
23
  @configuration ||= Dipps::Client::Configuration.new
23
24
  end
24
25
 
26
+ def perform_query(query:, result_field:, variables: {})
27
+ result = GraphqlClient.query(query, variables: variables)
28
+
29
+ if result.errors.any?
30
+ raise(Dipps::Client::Error, result.errors.details.inspect)
31
+ end
32
+
33
+ result.data.to_h.fetch(result_field)
34
+ end
35
+
25
36
  def create_own_invoice(freelance_profile_id:, attributes:)
26
- GraphqlClient.query(
27
- Dipps::Client::Queries::CreateOwnInvoice,
37
+ perform_query(
38
+ query: Dipps::Client::Queries::CreateOwnInvoice,
39
+ result_field: 'createOwnInvoice',
28
40
  variables: {
29
41
  freelance_profile_id: freelance_profile_id,
30
42
  attributes: attributes
31
43
  }
32
- ).data.to_h['createOwnInvoice']
44
+ )
33
45
  end
34
46
 
35
- def clients(org_number: nil, email: nil)
36
- GraphqlClient.query(
37
- Dipps::Client::Queries::Clients,
47
+ def clients(freelance_profile_id:, org_number: nil, email: nil)
48
+ perform_query(
49
+ query: Dipps::Client::Queries::Clients,
50
+ result_field: 'clients',
38
51
  variables: {
39
52
  orgNumber: org_number,
40
- email: email
53
+ email: email,
54
+ freelance_profile_id: freelance_profile_id
41
55
  }
42
- ).data.to_h['clients']
56
+ )
43
57
  end
44
58
 
45
59
  def create_client(attributes:)
46
- GraphqlClient.query(
47
- Dipps::Client::Queries::CreateClient,
60
+ perform_query(
61
+ query: Dipps::Client::Queries::CreateClient,
62
+ result_field: 'createClient',
48
63
  variables: {
49
64
  attributes: attributes
50
65
  }
51
- ).data.to_h['createClient']
66
+ )
52
67
  end
53
68
 
54
69
  def update_client(id:, attributes:)
55
- GraphqlClient.query(
56
- Dipps::Client::Queries::UpdateClient,
70
+ perform_query(
71
+ query: Dipps::Client::Queries::UpdateClient,
72
+ result_field: 'updateClient',
57
73
  variables: {
58
74
  id: id,
59
75
  attributes: attributes
60
76
  }
61
- ).data.to_h['updateClient']
77
+ )
62
78
  end
63
79
  end
64
80
  end