promptjoy-ruby 0.1.1 → 0.1.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -3
- data/lib/promptjoy-ruby/version.rb +1 -1
- data/lib/promptjoy-ruby.rb +12 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5cbf24cd878b9fd62c664a1033aa5961b8768e06069d40f85234e1e25d4210c
|
4
|
+
data.tar.gz: '0958ab3a92dc55778900be7a785b2d32818dd5b0b8eca6414b27b00a901039e7'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6d4d61af49df233f084f955ff22fa58df79f61e4d533613b94f80fb8ac64443c98863088356b130b71f4dd8fa7ef7af0bc5475b4b9917e26d3805c69afb6b4d
|
7
|
+
data.tar.gz: 1500f2211ce37c87d590a26810dcdc0cf8341a4019ca5340d51141ff9cb19590106a3913d8096522d1b70a67e61cdc20cacbf9965265584f8c0c21a7c63bd621
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,14 @@
|
|
2
2
|
|
3
3
|
Welcome to the official Ruby client for the [PromptJoy](https://promptjoy.com).
|
4
4
|
|
5
|
-
PromptJoy is a platform that enables you to build scalable APIs by simply describing what you want.
|
5
|
+
[PromptJoy](https://promptjoy.com) is a platform that enables you to build scalable APIs by simply describing what you want.
|
6
|
+
|
7
|
+
Example APIs built on [PromptJoy](https://promptjoy.com):
|
8
|
+
* Travel recommendation https://promptjoy.com/apis/mPBCOr
|
9
|
+
* TV show -> podcast recommendation: https://promptjoy.com/apis/mxqCWW
|
10
|
+
* Schema transformation: https://promptjoy.com/apis/jn8Cep
|
11
|
+
* Book search engine: https://promptjoy.com/apis/mVMCpq
|
12
|
+
|
6
13
|
|
7
14
|
## Installation
|
8
15
|
|
@@ -36,12 +43,16 @@ client = PromptjoyRuby::Client.new('your_api_key')
|
|
36
43
|
|
37
44
|
```
|
38
45
|
|
39
|
-
You can find the API you want to interact with by using its URL:
|
46
|
+
You can find the API you want to interact with by using its URL. You can find the URL in the endpoint field of the API's page:
|
40
47
|
|
41
48
|
```ruby
|
42
|
-
api = client.find_by_api_url('https://api.promptjoy.com/
|
49
|
+
api = client.find_by_api_url('https://api.promptjoy.com/api/id')
|
43
50
|
```
|
44
51
|
|
52
|
+
You can also just find the API by its id:
|
53
|
+
```ruby
|
54
|
+
api = client.find('id')
|
55
|
+
```
|
45
56
|
|
46
57
|
|
47
58
|
To call the API, pass in the data as a Hash:
|
@@ -53,6 +64,20 @@ response = api.call({
|
|
53
64
|
})
|
54
65
|
```
|
55
66
|
|
67
|
+
## Example
|
68
|
+
|
69
|
+
The following example uses PromptJoy to build an API that recommends an open-source software package based on a problem to be solved: https://promptjoy.com/apis/jNqC7A
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
> require 'promptjoy-ruby'
|
73
|
+
> client = PromptjoyRuby::Client.new('***********************')
|
74
|
+
> api = client.find_by_api_url('https://api.promptjoy.com/api/jNqC7A')
|
75
|
+
> response = api.call({problem: "queue processing in ruby"})
|
76
|
+
> puts response
|
77
|
+
|
78
|
+
{"software"=>"Sidekiq", "reason"=>"Efficient and reliable background processing
|
79
|
+
for Ruby", "github_url"=>"https://github.com/mperham/sidekiq"}
|
80
|
+
```
|
56
81
|
|
57
82
|
|
58
83
|
## Error Handling
|
data/lib/promptjoy-ruby.rb
CHANGED
@@ -10,7 +10,9 @@ module PromptjoyRuby
|
|
10
10
|
class Error < StandardError; end
|
11
11
|
|
12
12
|
class Client
|
13
|
-
|
13
|
+
BASE_API_URL = "https://api.promptjoy.com"
|
14
|
+
|
15
|
+
def initialize(api_key = nil, logger: Logger.new(STDOUT), timeout: 120)
|
14
16
|
@api_key = api_key
|
15
17
|
@logger = logger
|
16
18
|
end
|
@@ -18,12 +20,17 @@ module PromptjoyRuby
|
|
18
20
|
def find_by_api_url(url, api_key: nil)
|
19
21
|
Api.new(api_key || @api_key, url, logger: @logger)
|
20
22
|
end
|
23
|
+
|
24
|
+
def find(id)
|
25
|
+
url = "#{BASE_API_URL}/api/#{id}"
|
26
|
+
Api.new(@api_key, url, logger: @logger)
|
27
|
+
end
|
21
28
|
end
|
22
29
|
|
23
30
|
class Api
|
24
31
|
USER_AGENT = "PromptjoyRubyGem/#{PromptjoyRuby::VERSION}"
|
25
32
|
|
26
|
-
def initialize(api_key, url, logger: Logger.new(STDOUT))
|
33
|
+
def initialize(api_key, url, logger: Logger.new(STDOUT), timeout: 120)
|
27
34
|
@api_key = api_key
|
28
35
|
@url = url
|
29
36
|
@logger = logger
|
@@ -32,7 +39,9 @@ module PromptjoyRuby
|
|
32
39
|
def call(api_data, client_ip = nil, referrer = nil)
|
33
40
|
uri = URI(@url)
|
34
41
|
http = Net::HTTP.new(uri.host, uri.port)
|
35
|
-
|
42
|
+
http.open_timeout = @timeout
|
43
|
+
http.read_timeout = @timeout
|
44
|
+
|
36
45
|
if uri.scheme == 'https'
|
37
46
|
http.use_ssl = true
|
38
47
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promptjoy-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PromptJoy Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|