widgit_accounts_sdk 0.0.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: 8a59aef3a5e0413b6cce398b9bbde9c5bc8c058e12d5f95b94f549da7fc2a7f6
4
+ data.tar.gz: ca056e41a9891b1b5c6d6f016c1c12c88a35566979d031c7f365e1788eba9fc1
5
+ SHA512:
6
+ metadata.gz: 37c5d73075994e18cd8681cbf984cc4e117a9560a95cbcad51c8bf38fa87ce560c3a24a2b1e703d184bef386fea833a42169b64b164273c53ebf00fcadc8f0ba
7
+ data.tar.gz: 74d86331f5ab85917c974b29911ba6964ce69e327d0eb117c1bed0caf48a3ef5cb2ff7b5fbce575926f33c675d44a187e0eb656796a74a9b6ee4de819d610ebd
@@ -0,0 +1,94 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module WidgitAccountsSdk
5
+ module Client
6
+ extend self
7
+
8
+ def find_with_uid(uid)
9
+ response = request("/api/v1/accounts?uid=#{uid}")
10
+ return failed(response['error']) if response['status'] == 'failure'
11
+ return success.merge('account' => response.dig('data', 0))
12
+ end
13
+
14
+ def find_with_email(email)
15
+ response = request("/api/v1/accounts?email=#{email}")
16
+ return failed(response['error']) if response['status'] == 'failure'
17
+ return success.merge('account' => response.dig('data', 0))
18
+ end
19
+
20
+ def find_with_username(username)
21
+ response = request("/api/v1/accounts?username=#{username}")
22
+ return failed(response['error']) if response['status'] == 'failure'
23
+ return success.merge('account' => response.dig('data', 0))
24
+ end
25
+
26
+ def exists?(email)
27
+ response = request("/api/v1/accounts/check?email=#{email}")
28
+ return failed(response['error']) if response['status'] == 'failure'
29
+ return success.merge('exists' => response['exists'])
30
+ end
31
+
32
+ def invite(email, first_name, last_name)
33
+ response = request("/api/v1/accounts/invite?email=#{email}&first_name=#{first_name}&last_name=#{last_name}", :post)
34
+ return failed(response['error']) if response['status'] == 'failure'
35
+ return response
36
+ end
37
+
38
+ def get_new_invite_token(email)
39
+ response = request("/api/v1/accounts/invite?email=#{email}", :post)
40
+ return response['data']['invitation_token'] if response['status'] == 'success'
41
+ return nil
42
+ end
43
+
44
+ def create_account(params)
45
+ response = request("/api/v1/accounts", :post, params)
46
+ return failed(response['error']) if response['status'] == 'failure'
47
+ return response
48
+ end
49
+
50
+ def update_account(uid, params)
51
+ response = request("/api/v1/accounts/#{uid}", :patch, params)
52
+ return failed(response['error']) if response['status'] == 'failure'
53
+ return response
54
+ end
55
+
56
+ private
57
+ def request(path, method = :get, params = {})
58
+ uri = URI.parse("#{WidgitAccountsSdk.configuration.host}#{path}")
59
+ http = Net::HTTP.new(uri.host, uri.port)
60
+ http.use_ssl = (uri.scheme == "https")
61
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
62
+ http.open_timeout = 30
63
+ http.read_timeout = 30
64
+ case method
65
+ when :get
66
+ req = Net::HTTP::Get.new(uri.request_uri)
67
+ when :post
68
+ req = Net::HTTP::Post.new(uri.request_uri)
69
+ req.body = params.to_query
70
+ when :patch
71
+ req = Net::HTTP::Patch.new(uri.request_uri)
72
+ req.body = params.to_query
73
+ end
74
+ req["Authorization"] = WidgitAccountsSdk.configuration.api_key
75
+
76
+ begin
77
+ http.start do
78
+ res = http.request(req)
79
+ JSON.parse(res.body)
80
+ end
81
+ rescue => e
82
+ return failed(e)
83
+ end
84
+ end
85
+
86
+ def failed(e)
87
+ { 'status' => 'failed', 'error' => e }
88
+ end
89
+
90
+ def success
91
+ { 'status' => 'success' }
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,11 @@
1
+ module WidgitAccountsSdk
2
+ class Configuration
3
+ attr_accessor :host
4
+ attr_accessor :api_key
5
+
6
+ def initialize
7
+ @api_key = nil
8
+ @host = nil
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ require 'widgit_accounts_sdk/configuration'
2
+ require 'widgit_accounts_sdk/client'
3
+
4
+ module WidgitAccountsSdk
5
+ class << self
6
+ # Instantiate the Configuration singleton
7
+ # or return it. Remember that the instance
8
+ # has attribute readers so that we can access
9
+ # the configured values
10
+ def configuration
11
+ @configuration ||= Configuration.new
12
+ end
13
+
14
+ # This is the configure block definition.
15
+ # The configuration method will return the
16
+ # Configuration singleton, which is then yielded
17
+ # to the configure block. Then it's just a matter
18
+ # of using the attribute accessors we previously defined
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: widgit_accounts_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stu Wright
8
+ - James Sherriff
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2023-06-14 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A Ruby client for interacting with the Widgit Accounts API
15
+ email: james.sherriff@widgit.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/widgit_accounts_sdk.rb
21
+ - lib/widgit_accounts_sdk/client.rb
22
+ - lib/widgit_accounts_sdk/configuration.rb
23
+ homepage:
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 3.3.7
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Widgit Accounts API Client Ruby Gem
45
+ test_files: []