ruby-magicwrite 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78dec62f5b00bafdf4c419f17e5f908ce8431ed0d0ed1d5289a9b12556160990
4
- data.tar.gz: d707b12d56bca20072ab023ba01f8e7f12b86ad16b675e151c6b9fc9dcd2ea51
3
+ metadata.gz: fe492bf84e88d0fac86ee681671ab724a7247d37403301fcc6b2d24c5db23fb0
4
+ data.tar.gz: 67460bd0593a9e4b7503e6e048b42d0927631c62e784951056d629edc1e99666
5
5
  SHA512:
6
- metadata.gz: 218a31aab9ea79dd52f51dba0622d137ada3ee533532f49bdb06d1127aacd577873d9ea24ddca9fe7c0a50e8dca9a8c5731e4ce2c0996e4211fc270764a607b4
7
- data.tar.gz: 6dab53f804184b3e3179c1a51fb5cdf00493b2ec7781e59ed1e2982565797d42b8953473f3e0789b9ef590dc5e827fd344ad86f91fd8d6a2064250b8561c41ad
6
+ metadata.gz: d6a1b30d5c33d06fcd20eb1ce55e76326fc3889852824b331cc4da7ba8f2a65f1186cdbf44aff6180ba66afc6c2695a329d45ae2dc8edd85f1d141e3ec5f14a1
7
+ data.tar.gz: 564f7069e45f14f0370c634c65296d915032e9ac1a6c393724ef1aaa97187c85b222680ff6ab4a1909a0a7fd0753fe571114c0e0c4fb8f378f5c2d310d350b21
data/CHANGELOG.md CHANGED
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.1.5] - 2023-08-22
9
+
10
+ ### Added
11
+
12
+ - More specs to cover more implementations
13
+ - Refactor client and methods to use client in initalization
14
+ - include HTTP instead of extend for Client class
15
+
16
+ ## [0.1.4] - 2023-08-22
17
+
18
+ ### Added
19
+
20
+ - Memberships endpoints to MagicWrite client
21
+
22
+
23
+ ## [0.1.3] - 2023-08-21
24
+
25
+ ### Added
26
+
27
+ - General error classes by HTTP responses
28
+ - Error handler to parse the result
29
+
30
+
31
+ ### Changed
32
+
33
+ - README
34
+
35
+
8
36
  ## [0.1.2] - 2023-06-21
9
37
 
10
38
  ### Added
@@ -24,6 +52,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
24
52
 
25
53
  ### Added
26
54
 
27
- - Initialise repository.
55
+ - Initialize repository.
28
56
  - Add MagicWrite::Client to connect to MagicWrite API using user tokens.
57
+ * Completions
58
+ * Agents
59
+ * Companies
60
+ * Ingestions
61
+ * Session
29
62
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby-magicwrite (0.1.4)
4
+ ruby-magicwrite (0.1.5)
5
5
  faraday (>= 1)
6
6
  faraday-multipart (>= 1)
7
7
 
@@ -1,39 +1,43 @@
1
1
  module MagicWrite
2
2
  class Agents
3
- def initialize(access_token: nil)
4
- MagicWrite.configuration.access_token = access_token if access_token
3
+ def initialize(client:)
4
+ @client = client
5
5
  end
6
6
 
7
7
  def list(parameters: {})
8
- MagicWrite::Client.get(path: '/agents', parameters: parameters)
8
+ client.get(path: '/agents', parameters: parameters)
9
9
  end
10
10
 
11
11
  def create(parameters: {})
12
- MagicWrite::Client.json_post(path: '/agents', parameters: parameters)
12
+ client.json_post(path: '/agents', parameters: parameters)
13
13
  end
14
14
 
15
15
  def retrieve(id:)
16
- MagicWrite::Client.get(path: "/agents/#{id}")
16
+ client.get(path: "/agents/#{id}")
17
17
  end
18
18
 
19
19
  def update(id:, parameters: {})
20
- MagicWrite::Client.json_put(path: "/agents/#{id}", parameters: parameters)
20
+ client.json_put(path: "/agents/#{id}", parameters: parameters)
21
21
  end
22
22
 
23
23
  def delete(id:)
24
- MagicWrite::Client.delete(path: "/agents/#{id}")
24
+ client.delete(path: "/agents/#{id}")
25
25
  end
26
26
 
27
27
  def public_list(company_id:, parameters: {})
28
- MagicWrite::Client.get(path: "/agents/#{company_id}", parameters: parameters)
28
+ client.get(path: "/agents/#{company_id}", parameters: parameters)
29
29
  end
30
30
 
31
31
  def public_retrieve(company_id:, agent_id:)
32
- MagicWrite::Client.get(path: "/agents/#{company_id}/#{agent_id}")
32
+ client.get(path: "/agents/#{company_id}/#{agent_id}")
33
33
  end
34
34
 
35
35
  def public_create(company_id:, agent_id:, parameters: {})
36
- MagicWrite::Client.json_post(path: "/agents/#{company_id}/#{agent_id}", parameters: parameters)
36
+ client.json_post(path: "/agents/#{company_id}/#{agent_id}", parameters: parameters)
37
37
  end
38
+
39
+ private
40
+
41
+ attr_reader :client
38
42
  end
39
43
  end
@@ -1,35 +1,43 @@
1
1
  module MagicWrite
2
2
  class Client
3
- extend MagicWrite::HTTP
3
+ include MagicWrite::HTTP
4
4
 
5
- def initialize(access_token: nil, uri_base: nil, request_timeout: nil)
6
- MagicWrite.configuration.access_token = access_token if access_token
7
- MagicWrite.configuration.uri_base = uri_base if uri_base
8
- MagicWrite.configuration.request_timeout = request_timeout if request_timeout
5
+ CONFIG_KEYS = %i[
6
+ access_token
7
+ uri_base
8
+ request_timeout
9
+ extra_headers
10
+ ].freeze
11
+ attr_reader(*CONFIG_KEYS)
12
+
13
+ def initialize(config = {})
14
+ CONFIG_KEYS.each do |key|
15
+ instance_variable_set("@#{key}", config[key] || MagicWrite.configuration.send(key))
16
+ end
9
17
  end
10
18
 
11
19
  def agents
12
- @agents ||= MagicWrite::Agents.new
20
+ @agents ||= MagicWrite::Agents.new(client: self)
13
21
  end
14
22
 
15
23
  def companies
16
- @companies ||= MagicWrite::Companies.new
24
+ @companies ||= MagicWrite::Companies.new(client: self)
17
25
  end
18
26
 
19
27
  def completions
20
- @completions ||= MagicWrite::Completions.new
28
+ @completions ||= MagicWrite::Completions.new(client: self)
21
29
  end
22
30
 
23
31
  def ingestions
24
- @ingestions ||= MagicWrite::Ingestions.new
32
+ @ingestions ||= MagicWrite::Ingestions.new(client: self)
25
33
  end
26
34
 
27
35
  def memberships
28
- @memberships ||= MagicWrite::Memberships.new
36
+ @memberships ||= MagicWrite::Memberships.new(client: self)
29
37
  end
30
38
 
31
39
  def session
32
- MagicWrite::Client.get(path: '/session')
40
+ get(path: '/session')
33
41
  end
34
42
  end
35
43
  end
@@ -1,19 +1,23 @@
1
1
  module MagicWrite
2
2
  class Companies
3
- def initialize(access_token: nil)
4
- MagicWrite.configuration.access_token = access_token if access_token
3
+ def initialize(client:)
4
+ @client = client
5
5
  end
6
6
 
7
7
  def create(parameters: {})
8
- MagicWrite::Client.json_post(path: '/companies', parameters: parameters)
8
+ client.json_post(path: '/companies', parameters: parameters)
9
9
  end
10
10
 
11
11
  def retrieve
12
- MagicWrite::Client.get(path: '/companies/current')
12
+ client.get(path: '/companies/current')
13
13
  end
14
14
 
15
15
  def update(parameters: {})
16
- MagicWrite::Client.json_put(path: '/companies/current', parameters: parameters)
16
+ client.json_put(path: '/companies/current', parameters: parameters)
17
17
  end
18
+
19
+ private
20
+
21
+ attr_reader :client
18
22
  end
19
23
  end
@@ -1,23 +1,27 @@
1
1
  module MagicWrite
2
2
  class Completions
3
- def initialize(access_token: nil)
4
- MagicWrite.configuration.access_token = access_token if access_token
3
+ def initialize(client:)
4
+ @client = client
5
5
  end
6
6
 
7
7
  def execute(parameters: {})
8
- MagicWrite::Client.json_post(path: '/completions', parameters: parameters)
8
+ client.json_post(path: '/completions', parameters: parameters)
9
9
  end
10
10
 
11
11
  def retrieve(id:, parameters: {})
12
- MagicWrite::Client.get(path: "/completions/#{id}", parameters: parameters)
12
+ client.get(path: "/completions/#{id}", parameters: parameters)
13
13
  end
14
14
 
15
15
  def create(id:, parameters: {})
16
- MagicWrite::Client.json_post(path: "/completions/#{id}", parameters: parameters)
16
+ client.json_post(path: "/completions/#{id}", parameters: parameters)
17
17
  end
18
18
 
19
19
  def delete(id:, completion_id:)
20
- MagicWrite::Client.delete(path: "/completions/#{id}/#{completion_id}")
20
+ client.delete(path: "/completions/#{id}/#{completion_id}")
21
21
  end
22
+
23
+ private
24
+
25
+ attr_reader :client
22
26
  end
23
27
  end
@@ -82,20 +82,20 @@ module MagicWrite
82
82
 
83
83
  def conn(multipart: false)
84
84
  Faraday.new do |faraday|
85
- faraday.options[:timeout] = MagicWrite.configuration.request_timeout
85
+ faraday.options[:timeout] = @request_timeout
86
86
  faraday.request(:multipart) if multipart
87
87
  end
88
88
  end
89
89
 
90
90
  def uri(path:)
91
- File.join(MagicWrite.configuration.uri_base, path)
91
+ File.join(@uri_base, path)
92
92
  end
93
93
 
94
94
  def headers
95
95
  {
96
96
  'Content-Type' => 'application/json',
97
- 'Authorization' => "Bearer #{MagicWrite.configuration.access_token}"
98
- }
97
+ 'Authorization' => "Bearer #{@access_token}"
98
+ }.merge(@extra_headers || {})
99
99
  end
100
100
 
101
101
  def multipart_parameters(parameters)
@@ -1,23 +1,27 @@
1
1
  module MagicWrite
2
2
  class Ingestions
3
- def initialize(access_token: nil)
4
- MagicWrite.configuration.access_token = access_token if access_token
3
+ def initialize(client:)
4
+ @client = client
5
5
  end
6
6
 
7
7
  def list(parameters: {})
8
- MagicWrite::Client.get(path: '/ingestions', parameters: parameters)
8
+ client.get(path: '/ingestions', parameters: parameters)
9
9
  end
10
10
 
11
11
  def create(parameters: {})
12
- MagicWrite::Client.json_post(path: '/ingestions', parameters: parameters)
12
+ client.json_post(path: '/ingestions', parameters: parameters)
13
13
  end
14
14
 
15
15
  def retrieve(id:)
16
- MagicWrite::Client.get(path: "/ingestions/#{id}")
16
+ client.get(path: "/ingestions/#{id}")
17
17
  end
18
18
 
19
19
  def delete(id:)
20
- MagicWrite::Client.delete(path: "/ingestions/#{id}")
20
+ client.delete(path: "/ingestions/#{id}")
21
21
  end
22
+
23
+ private
24
+
25
+ attr_reader :client
22
26
  end
23
27
  end
@@ -1,15 +1,19 @@
1
1
  module MagicWrite
2
2
  class Memberships
3
- def initialize(access_token: nil)
4
- MagicWrite.configuration.access_token = access_token if access_token
3
+ def initialize(client:)
4
+ @client = client
5
5
  end
6
6
 
7
7
  def user
8
- MagicWrite::Client.get(path: '/memberships/user')
8
+ client.get(path: '/memberships/user')
9
9
  end
10
10
 
11
11
  def company
12
- MagicWrite::Client.get(path: '/memberships/company')
12
+ client.get(path: '/memberships/company')
13
13
  end
14
+
15
+ private
16
+
17
+ attr_reader :client
14
18
  end
15
19
  end
@@ -1,3 +1,3 @@
1
1
  module MagicWrite
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
data/lib/magicwrite.rb CHANGED
@@ -17,7 +17,7 @@ module MagicWrite
17
17
 
18
18
  class Configuration
19
19
  attr_writer :access_token
20
- attr_accessor :uri_base, :request_timeout
20
+ attr_accessor :uri_base, :request_timeout, :extra_headers
21
21
 
22
22
  DEFAULT_URI_BASE = 'https://api.magicwrite.ai/rest/'.freeze
23
23
  DEFAULT_REQUEST_TIMEOUT = 120
@@ -26,6 +26,7 @@ module MagicWrite
26
26
  @access_token = nil
27
27
  @uri_base = DEFAULT_URI_BASE
28
28
  @request_timeout = DEFAULT_REQUEST_TIMEOUT
29
+ @extra_headers = nil
29
30
  end
30
31
 
31
32
  def access_token
@@ -38,13 +39,13 @@ module MagicWrite
38
39
 
39
40
  class << self
40
41
  attr_writer :configuration
41
- end
42
42
 
43
- def self.configuration
44
- @configuration ||= MagicWrite::Configuration.new
45
- end
43
+ def configuration
44
+ @configuration ||= MagicWrite::Configuration.new
45
+ end
46
46
 
47
- def self.configure
48
- yield(configuration)
47
+ def configure
48
+ yield(configuration)
49
+ end
49
50
  end
50
51
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-magicwrite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Campos