ruby-magicwrite 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/dependabot.yml +15 -0
- data/.gitignore +16 -0
- data/.rspec +3 -0
- data/.rubocop.yml +30 -0
- data/CHANGELOG.md +14 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/magicwrite/agents.rb +39 -0
- data/lib/magicwrite/client.rb +31 -0
- data/lib/magicwrite/companies.rb +19 -0
- data/lib/magicwrite/compatibility.rb +9 -0
- data/lib/magicwrite/completions.rb +23 -0
- data/lib/magicwrite/http.rb +109 -0
- data/lib/magicwrite/ingestions.rb +23 -0
- data/lib/magicwrite/version.rb +3 -0
- data/lib/magicwrite.rb +48 -0
- data/lib/ruby/magicwrite.rb +2 -0
- data/pull_request_template.md +5 -0
- data/ruby-magicwrite.gemspec +30 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 900f6dc8e52e9c2c4f69dbf3fab75bd5b11bc68bc0eaee46ae690895913a3ff4
|
4
|
+
data.tar.gz: cfe2b116bb9a1c42c737b80d4392cfef0e43c1bbb400f4e06809130bbe096864
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 29771cba1cf7062bf7b1931c163f50d0d88ed2efaf8960cf4f2f53b60093df82d23553b03e21d97641b1b766e1bfb7fdd782fc76e2f24868f50fa979fca425a5
|
7
|
+
data.tar.gz: c4904a87fd42af27c4bfb51994d93324444c6a143838e980fdd9fbb49ff70dfa1ed192101e4c879d085a4a280a73a71a9537ce07df44fdac2725e4354cdb5dc9
|
@@ -0,0 +1,38 @@
|
|
1
|
+
---
|
2
|
+
name: Bug report
|
3
|
+
about: Create a report to help us improve
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Describe the bug**
|
11
|
+
A clear and concise description of what the bug is.
|
12
|
+
|
13
|
+
**To Reproduce**
|
14
|
+
Steps to reproduce the behavior:
|
15
|
+
1. Go to '...'
|
16
|
+
2. Click on '....'
|
17
|
+
3. Scroll down to '....'
|
18
|
+
4. See error
|
19
|
+
|
20
|
+
**Expected behavior**
|
21
|
+
A clear and concise description of what you expected to happen.
|
22
|
+
|
23
|
+
**Screenshots**
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
25
|
+
|
26
|
+
**Desktop (please complete the following information):**
|
27
|
+
- OS: [e.g. iOS]
|
28
|
+
- Browser [e.g. chrome, safari]
|
29
|
+
- Version [e.g. 22]
|
30
|
+
|
31
|
+
**Smartphone (please complete the following information):**
|
32
|
+
- Device: [e.g. iPhone6]
|
33
|
+
- OS: [e.g. iOS8.1]
|
34
|
+
- Browser [e.g. stock browser, safari]
|
35
|
+
- Version [e.g. 22]
|
36
|
+
|
37
|
+
**Additional context**
|
38
|
+
Add any other context about the problem here.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
---
|
2
|
+
name: Feature request
|
3
|
+
about: Suggest an idea for this project
|
4
|
+
title: ''
|
5
|
+
labels: ''
|
6
|
+
assignees: ''
|
7
|
+
|
8
|
+
---
|
9
|
+
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
12
|
+
|
13
|
+
**Describe the solution you'd like**
|
14
|
+
A clear and concise description of what you want to happen.
|
15
|
+
|
16
|
+
**Describe alternatives you've considered**
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
18
|
+
|
19
|
+
**Additional context**
|
20
|
+
Add any other context or screenshots about the feature request here.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
version: 2
|
2
|
+
updates:
|
3
|
+
- package-ecosystem: bundler
|
4
|
+
directory: "/"
|
5
|
+
schedule:
|
6
|
+
interval: daily
|
7
|
+
open-pull-requests-limit: 10
|
8
|
+
ignore:
|
9
|
+
- dependency-name: webmock
|
10
|
+
versions:
|
11
|
+
- 3.11.1
|
12
|
+
- 3.11.3
|
13
|
+
- dependency-name: rspec
|
14
|
+
versions:
|
15
|
+
- 3.10.0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
AllCops:
|
2
|
+
DisplayStyleGuide: true
|
3
|
+
TargetRubyVersion: 2.6
|
4
|
+
NewCops: enable
|
5
|
+
SuggestExtensions: false
|
6
|
+
|
7
|
+
Gemspec/DeprecatedAttributeAssignment:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Style/Documentation:
|
11
|
+
# Skips checking to make sure top level modules / classes have a comment.
|
12
|
+
Enabled: false
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Max: 120
|
16
|
+
Exclude:
|
17
|
+
- "**/*.gemspec"
|
18
|
+
|
19
|
+
Metrics/AbcSize:
|
20
|
+
Max: 20
|
21
|
+
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Exclude:
|
24
|
+
- "spec/**/*"
|
25
|
+
|
26
|
+
Style/StringLiterals:
|
27
|
+
EnforcedStyle: single_quotes
|
28
|
+
|
29
|
+
Style/FrozenStringLiteralComment:
|
30
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [0.1.0] - 2023-06-21
|
9
|
+
|
10
|
+
### Added
|
11
|
+
|
12
|
+
- Initialise repository.
|
13
|
+
- Add MagicWrite::Client to connect to OpenAI API using user tokens.
|
14
|
+
- Add spec for Client with a cached response using VCR.
|
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Include gem dependencies from ruby-magicwrite.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem 'byebug', '~> 11.1.3'
|
7
|
+
gem 'dotenv', '~> 2.8.1'
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
gem 'rspec', '~> 3.12'
|
10
|
+
gem 'rubocop', '~> 1.50.2'
|
11
|
+
gem 'vcr', '~> 6.1.0'
|
12
|
+
gem 'webmock', '~> 3.18.1'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby-magicwrite (0.1.0)
|
5
|
+
faraday (>= 1)
|
6
|
+
faraday-multipart (>= 1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.4)
|
12
|
+
public_suffix (>= 2.0.2, < 6.0)
|
13
|
+
ast (2.4.2)
|
14
|
+
byebug (11.1.3)
|
15
|
+
crack (0.4.5)
|
16
|
+
rexml
|
17
|
+
diff-lcs (1.5.0)
|
18
|
+
dotenv (2.8.1)
|
19
|
+
faraday (2.7.4)
|
20
|
+
faraday-net_http (>= 2.0, < 3.1)
|
21
|
+
ruby2_keywords (>= 0.0.4)
|
22
|
+
faraday-multipart (1.0.4)
|
23
|
+
multipart-post (~> 2)
|
24
|
+
faraday-net_http (3.0.2)
|
25
|
+
hashdiff (1.0.1)
|
26
|
+
json (2.6.3)
|
27
|
+
multipart-post (2.2.3)
|
28
|
+
parallel (1.23.0)
|
29
|
+
parser (3.2.2.1)
|
30
|
+
ast (~> 2.4.1)
|
31
|
+
public_suffix (5.0.1)
|
32
|
+
rainbow (3.1.1)
|
33
|
+
rake (13.0.6)
|
34
|
+
regexp_parser (2.8.0)
|
35
|
+
rexml (3.2.5)
|
36
|
+
rspec (3.12.0)
|
37
|
+
rspec-core (~> 3.12.0)
|
38
|
+
rspec-expectations (~> 3.12.0)
|
39
|
+
rspec-mocks (~> 3.12.0)
|
40
|
+
rspec-core (3.12.2)
|
41
|
+
rspec-support (~> 3.12.0)
|
42
|
+
rspec-expectations (3.12.3)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.12.0)
|
45
|
+
rspec-mocks (3.12.5)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.12.0)
|
48
|
+
rspec-support (3.12.0)
|
49
|
+
rubocop (1.50.2)
|
50
|
+
json (~> 2.3)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.2.0.0)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.8, < 3.0)
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.28.1)
|
60
|
+
parser (>= 3.2.1.0)
|
61
|
+
ruby-progressbar (1.13.0)
|
62
|
+
ruby2_keywords (0.0.5)
|
63
|
+
unicode-display_width (2.4.2)
|
64
|
+
vcr (6.1.0)
|
65
|
+
webmock (3.18.1)
|
66
|
+
addressable (>= 2.8.0)
|
67
|
+
crack (>= 0.3.2)
|
68
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
69
|
+
|
70
|
+
PLATFORMS
|
71
|
+
x86_64-linux
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
byebug (~> 11.1.3)
|
75
|
+
dotenv (~> 2.8.1)
|
76
|
+
rake (~> 13.0)
|
77
|
+
rspec (~> 3.12)
|
78
|
+
rubocop (~> 1.50.2)
|
79
|
+
ruby-magicwrite!
|
80
|
+
vcr (~> 6.1.0)
|
81
|
+
webmock (~> 3.18.1)
|
82
|
+
|
83
|
+
BUNDLED WITH
|
84
|
+
2.2.32
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Alex
|
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,47 @@
|
|
1
|
+
# Ruby MagicWrite
|
2
|
+
|
3
|
+
Use the [MagicWrite API](https://developers.magicwrite.ai/) with Ruby! 🤖❤️
|
4
|
+
|
5
|
+
### Bundler
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "ruby-magicwrite"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
### Gem install
|
18
|
+
|
19
|
+
Or install with:
|
20
|
+
|
21
|
+
$ gem install ruby-magicwrite
|
22
|
+
|
23
|
+
and require with:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require "magicwrite"
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
|
32
|
+
### Quickstart
|
33
|
+
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at <https://github.com/kykocamp/ruby-magicwrite>.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'magicwrite'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
class Agents
|
3
|
+
def initialize(access_token: nil)
|
4
|
+
MagicWrite.configuration.access_token = access_token if access_token
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(parameters: {})
|
8
|
+
MagicWrite::Client.get(path: '/agents', parameters: parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(parameters: {})
|
12
|
+
MagicWrite::Client.json_post(path: '/agents', parameters: parameters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve(id:)
|
16
|
+
MagicWrite::Client.get(path: "/agents/#{id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(id:, parameters: {})
|
20
|
+
MagicWrite::Client.json_put(path: "/agents/#{id}", parameters: parameters)
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(id:)
|
24
|
+
MagicWrite::Client.delete(path: "/agents/#{id}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def public_list(company_id:, parameters: {})
|
28
|
+
MagicWrite::Client.get(path: "/agents/#{company_id}", parameters: parameters)
|
29
|
+
end
|
30
|
+
|
31
|
+
def public_retrieve(company_id:, agent_id:)
|
32
|
+
MagicWrite::Client.get(path: "/agents/#{company_id}/#{agent_id}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def public_create(company_id:, agent_id:, parameters: {})
|
36
|
+
MagicWrite::Client.json_post(path: "/agents/#{company_id}/#{agent_id}", parameters: parameters)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
class Client
|
3
|
+
extend MagicWrite::HTTP
|
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
|
9
|
+
end
|
10
|
+
|
11
|
+
def agents
|
12
|
+
@agents ||= MagicWrite::Agents.new
|
13
|
+
end
|
14
|
+
|
15
|
+
def companies
|
16
|
+
@companies ||= MagicWrite::Companies.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def completions
|
20
|
+
@completions ||= MagicWrite::Completions.new
|
21
|
+
end
|
22
|
+
|
23
|
+
def ingestions
|
24
|
+
@ingestions ||= MagicWrite::Ingestions.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def session
|
28
|
+
MagicWrite::Client.get(path: '/session')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
class Companies
|
3
|
+
def initialize(access_token: nil)
|
4
|
+
MagicWrite.configuration.access_token = access_token if access_token
|
5
|
+
end
|
6
|
+
|
7
|
+
def create(parameters: {})
|
8
|
+
MagicWrite::Client.json_post(path: '/companies', parameters: parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve
|
12
|
+
MagicWrite::Client.get(path: '/companies/current')
|
13
|
+
end
|
14
|
+
|
15
|
+
def update(parameters: {})
|
16
|
+
MagicWrite::Client.json_put(path: '/companies/current', parameters: parameters)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
class Completions
|
3
|
+
def initialize(access_token: nil)
|
4
|
+
MagicWrite.configuration.access_token = access_token if access_token
|
5
|
+
end
|
6
|
+
|
7
|
+
def execute(parameters: {})
|
8
|
+
MagicWrite::Client.json_post(path: '/completions', parameters: parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def retrieve(id:, parameters: {})
|
12
|
+
MagicWrite::Client.get(path: "/completions/#{id}", parameters: parameters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(id:, parameters: {})
|
16
|
+
MagicWrite::Client.json_post(path: "/completions/#{id}", parameters: parameters)
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(id:, completion_id:)
|
20
|
+
MagicWrite::Client.delete(path: "/completions/#{id}/#{completion_id}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
module HTTP
|
3
|
+
def get(path:, parameters: {})
|
4
|
+
to_json(conn.get(uri(path: path)) do |req|
|
5
|
+
req.headers = headers
|
6
|
+
req.body = parameters.to_json
|
7
|
+
end&.body)
|
8
|
+
end
|
9
|
+
|
10
|
+
def json_post(path:, parameters:)
|
11
|
+
to_json(conn.post(uri(path: path)) do |req|
|
12
|
+
if parameters[:stream].respond_to?(:call)
|
13
|
+
req.options.on_data = to_json_stream(user_proc: parameters[:stream])
|
14
|
+
parameters[:stream] = true
|
15
|
+
elsif parameters[:stream]
|
16
|
+
raise ArgumentError, 'The stream parameter must be a Proc or have a #call method'
|
17
|
+
end
|
18
|
+
|
19
|
+
req.headers = headers
|
20
|
+
req.body = parameters.to_json
|
21
|
+
end&.body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def json_put(path:, parameters:)
|
25
|
+
to_json(conn.put(uri(path: path)) do |req|
|
26
|
+
if parameters[:stream].respond_to?(:call)
|
27
|
+
req.options.on_data = to_json_stream(user_proc: parameters[:stream])
|
28
|
+
parameters[:stream] = true
|
29
|
+
elsif parameters[:stream]
|
30
|
+
raise ArgumentError, 'The stream parameter must be a Proc or have a #call method'
|
31
|
+
end
|
32
|
+
|
33
|
+
req.headers = headers
|
34
|
+
req.body = parameters.to_json
|
35
|
+
end&.body)
|
36
|
+
end
|
37
|
+
|
38
|
+
def multipart_post(path:, parameters: nil)
|
39
|
+
to_json(conn(multipart: true).post(uri(path: path)) do |req|
|
40
|
+
req.headers = headers.merge({ 'Content-Type' => 'multipart/form-data' })
|
41
|
+
req.body = multipart_parameters(parameters)
|
42
|
+
end&.body)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete(path:)
|
46
|
+
to_json(conn.delete(uri(path: path)) do |req|
|
47
|
+
req.headers = headers
|
48
|
+
end&.body)
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def to_json(string)
|
54
|
+
return unless string
|
55
|
+
|
56
|
+
JSON.parse(string)
|
57
|
+
rescue JSON::ParserError
|
58
|
+
# Convert a multiline string of JSON objects to a JSON array.
|
59
|
+
JSON.parse(string.gsub("}\n{", '},{').prepend('[').concat(']'))
|
60
|
+
end
|
61
|
+
|
62
|
+
# Given a proc, returns an outer proc that can be used to iterate over a JSON stream of chunks.
|
63
|
+
# For each chunk, the inner user_proc is called giving it the JSON object. The JSON object could
|
64
|
+
# be a data object or an error object as described in the OpenAI API documentation.
|
65
|
+
#
|
66
|
+
# If the JSON object for a given data or error message is invalid, it is ignored.
|
67
|
+
#
|
68
|
+
# @param user_proc [Proc] The inner proc to call for each JSON object in the chunk.
|
69
|
+
# @return [Proc] An outer proc that iterates over a raw stream, converting it to JSON.
|
70
|
+
def to_json_stream(user_proc:)
|
71
|
+
proc do |chunk, _|
|
72
|
+
chunk.scan(/(?:data|error): (\{.*\})/i).flatten.each do |data|
|
73
|
+
user_proc.call(JSON.parse(data))
|
74
|
+
rescue JSON::ParserError
|
75
|
+
# Ignore invalid JSON.
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def conn(multipart: false)
|
81
|
+
Faraday.new do |f|
|
82
|
+
f.options[:timeout] = MagicWrite.configuration.request_timeout
|
83
|
+
f.request(:multipart) if multipart
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def uri(path:)
|
88
|
+
File.join(MagicWrite.configuration.uri_base, path)
|
89
|
+
end
|
90
|
+
|
91
|
+
def headers
|
92
|
+
{
|
93
|
+
'Content-Type' => 'application/json',
|
94
|
+
'Authorization' => "Bearer #{MagicWrite.configuration.access_token}"
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def multipart_parameters(parameters)
|
99
|
+
parameters&.transform_values do |value|
|
100
|
+
next value unless value.is_a?(File)
|
101
|
+
|
102
|
+
# Doesn't seem like OpenAI need mime_type yet, so not worth
|
103
|
+
# the library to figure this out. Hence the empty string
|
104
|
+
# as the second argument.
|
105
|
+
Faraday::UploadIO.new(value, '', value.path)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module MagicWrite
|
2
|
+
class Ingestions
|
3
|
+
def initialize(access_token: nil)
|
4
|
+
MagicWrite.configuration.access_token = access_token if access_token
|
5
|
+
end
|
6
|
+
|
7
|
+
def list(parameters: {})
|
8
|
+
MagicWrite::Client.get(path: '/ingestions', parameters: parameters)
|
9
|
+
end
|
10
|
+
|
11
|
+
def create(parameters: {})
|
12
|
+
MagicWrite::Client.json_post(path: '/ingestions', parameters: parameters)
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve(id:)
|
16
|
+
MagicWrite::Client.get(path: "/ingestions/#{id}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(id:)
|
20
|
+
MagicWrite::Client.delete(path: "/ingestions/#{id}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/magicwrite.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday/multipart'
|
3
|
+
|
4
|
+
require_relative 'magicwrite/http'
|
5
|
+
require_relative 'magicwrite/client'
|
6
|
+
require_relative 'magicwrite/agents'
|
7
|
+
require_relative 'magicwrite/companies'
|
8
|
+
require_relative 'magicwrite/completions'
|
9
|
+
require_relative 'magicwrite/ingestions'
|
10
|
+
require_relative 'magicwrite/version'
|
11
|
+
|
12
|
+
module MagicWrite
|
13
|
+
class Error < StandardError; end
|
14
|
+
class ConfigurationError < Error; end
|
15
|
+
|
16
|
+
class Configuration
|
17
|
+
attr_writer :access_token
|
18
|
+
attr_accessor :uri_base, :request_timeout
|
19
|
+
|
20
|
+
DEFAULT_URI_BASE = 'https://api.magicwrite.ai/rest/'.freeze
|
21
|
+
DEFAULT_REQUEST_TIMEOUT = 120
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@access_token = nil
|
25
|
+
@uri_base = DEFAULT_URI_BASE
|
26
|
+
@request_timeout = DEFAULT_REQUEST_TIMEOUT
|
27
|
+
end
|
28
|
+
|
29
|
+
def access_token
|
30
|
+
return @access_token if @access_token
|
31
|
+
|
32
|
+
error_text = 'MagicWrite access token missing! See https://github.com/kykocamp/ruby-magicwrite#usage'
|
33
|
+
raise ConfigurationError, error_text
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class << self
|
38
|
+
attr_writer :configuration
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.configuration
|
42
|
+
@configuration ||= MagicWrite::Configuration.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.configure
|
46
|
+
yield(configuration)
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
## All Submissions:
|
2
|
+
|
3
|
+
* [ ] Have you followed the guidelines in our [Contributing document](../blob/main/CONTRIBUTING.md)?
|
4
|
+
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../pulls) for the same update/change?
|
5
|
+
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/magicwrite/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'ruby-magicwrite'
|
5
|
+
spec.version = MagicWrite::VERSION
|
6
|
+
spec.authors = ['Rodrigo Campos', 'Rodolfo Spalenza']
|
7
|
+
spec.email = ['rodrigo.campos@rdstation.com', 'rodolfo.spalenza@rdstation.com']
|
8
|
+
|
9
|
+
spec.summary = 'MagicWrite API + Ruby! 🤖❤️'
|
10
|
+
spec.homepage = 'https://github.com/kykocamp/ruby-magicwrite'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
13
|
+
|
14
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
15
|
+
spec.metadata['source_code_uri'] = 'https://github.com/kykocamp/ruby-magicwrite'
|
16
|
+
spec.metadata['changelog_uri'] = 'https://github.com/kykocamp/ruby-magicwrite/blob/main/CHANGELOG.md'
|
17
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '>= 1'
|
29
|
+
spec.add_dependency 'faraday-multipart', '>= 1'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-magicwrite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodrigo Campos
|
8
|
+
- Rodolfo Spalenza
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: faraday-multipart
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1'
|
42
|
+
description:
|
43
|
+
email:
|
44
|
+
- rodrigo.campos@rdstation.com
|
45
|
+
- rodolfo.spalenza@rdstation.com
|
46
|
+
executables: []
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
51
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
52
|
+
- ".github/dependabot.yml"
|
53
|
+
- ".gitignore"
|
54
|
+
- ".rspec"
|
55
|
+
- ".rubocop.yml"
|
56
|
+
- CHANGELOG.md
|
57
|
+
- CONTRIBUTING.md
|
58
|
+
- Gemfile
|
59
|
+
- Gemfile.lock
|
60
|
+
- LICENSE.txt
|
61
|
+
- README.md
|
62
|
+
- Rakefile
|
63
|
+
- bin/console
|
64
|
+
- bin/setup
|
65
|
+
- lib/magicwrite.rb
|
66
|
+
- lib/magicwrite/agents.rb
|
67
|
+
- lib/magicwrite/client.rb
|
68
|
+
- lib/magicwrite/companies.rb
|
69
|
+
- lib/magicwrite/compatibility.rb
|
70
|
+
- lib/magicwrite/completions.rb
|
71
|
+
- lib/magicwrite/http.rb
|
72
|
+
- lib/magicwrite/ingestions.rb
|
73
|
+
- lib/magicwrite/version.rb
|
74
|
+
- lib/ruby/magicwrite.rb
|
75
|
+
- pull_request_template.md
|
76
|
+
- ruby-magicwrite.gemspec
|
77
|
+
homepage: https://github.com/kykocamp/ruby-magicwrite
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata:
|
81
|
+
homepage_uri: https://github.com/kykocamp/ruby-magicwrite
|
82
|
+
source_code_uri: https://github.com/kykocamp/ruby-magicwrite
|
83
|
+
changelog_uri: https://github.com/kykocamp/ruby-magicwrite/blob/main/CHANGELOG.md
|
84
|
+
rubygems_mfa_required: 'true'
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.6.0
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.1.6
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: "MagicWrite API + Ruby! \U0001F916❤️"
|
104
|
+
test_files: []
|