promptjoy-ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 310a49711f3259ee888236d1e463e7dbe800d9e984da38c22050f3e98dd8293d
4
+ data.tar.gz: ba442e4c722d1cb91be33204590bf532dccb8e72a2caf70c796d1c8cb66d3508
5
+ SHA512:
6
+ metadata.gz: beda92c16b2d6f34955f2ff2bb85ebe0c17dae1dd4dfb9dc05ae95ca1d3ea2ee1201c387658794d36115416a15ab400fd139f3c5aa1586f2ce88e677be1067fd
7
+ data.tar.gz: a9c24e4fba7592862c0acddaff3fc67c4eaf8d035e02cb4b0f7b88603c1060a36e154ab00dd74540a0dc62f90a12a7b8c78e50edc8ff75611e1f047ac700ecff
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in promptjoy-ruby.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ promptjoy-ruby (0.1.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.4)
10
+ public_suffix (>= 2.0.2, < 6.0)
11
+ crack (0.4.5)
12
+ rexml
13
+ diff-lcs (1.5.0)
14
+ hashdiff (1.0.1)
15
+ public_suffix (5.0.3)
16
+ rake (13.0.6)
17
+ rexml (3.2.5)
18
+ rspec (3.12.0)
19
+ rspec-core (~> 3.12.0)
20
+ rspec-expectations (~> 3.12.0)
21
+ rspec-mocks (~> 3.12.0)
22
+ rspec-core (3.12.2)
23
+ rspec-support (~> 3.12.0)
24
+ rspec-expectations (3.12.3)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.12.0)
27
+ rspec-mocks (3.12.6)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.12.0)
30
+ rspec-support (3.12.1)
31
+ webmock (3.18.1)
32
+ addressable (>= 2.8.0)
33
+ crack (>= 0.3.2)
34
+ hashdiff (>= 0.4.0, < 2.0.0)
35
+
36
+ PLATFORMS
37
+ arm64-darwin-21
38
+
39
+ DEPENDENCIES
40
+ promptjoy-ruby!
41
+ rake (~> 13.0)
42
+ rspec (~> 3.0)
43
+ webmock (~> 3.0)
44
+
45
+ BUNDLED WITH
46
+ 2.3.26
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 PromptJoy
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,81 @@
1
+ # PromptJoy Ruby Gem
2
+
3
+ Welcome to the official Ruby client for the [PromptJoy](https://promptjoy.com).
4
+
5
+ PromptJoy is a platform that enables you to build scalable APIs by simply describing what you want. This client helps you interact with PromptJoy in a Ruby-friendly way.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'promptjoy-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```bash
24
+ gem install promptjoy-ruby
25
+ ```
26
+
27
+
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'promptjoy-ruby'
33
+
34
+ client = PromptjoyRuby::Client.new('your_api_key')
35
+
36
+
37
+ ```
38
+
39
+ You can find the API you want to interact with by using its URL:
40
+
41
+ ```ruby
42
+ api = client.find_by_api_url('https://api.promptjoy.com/test-endpoint')
43
+ ```
44
+
45
+
46
+
47
+ To call the API, pass in the data as a Hash:
48
+
49
+ ```ruby
50
+ response = api.call({
51
+ key1: 'value1',
52
+ key2: 'value2'
53
+ })
54
+ ```
55
+
56
+
57
+
58
+ ## Error Handling
59
+
60
+ If an error occurs during an API call, an instance of PromptjoyRuby::Error is raised with a message indicating the nature of the error.
61
+
62
+ ```ruby
63
+ begin
64
+ api.call(some_data)
65
+ rescue PromptjoyRuby::Error => e
66
+ puts "An error occurred: #{e.message}"
67
+ end
68
+ ```
69
+
70
+
71
+
72
+
73
+ ## More about PromptJoy
74
+
75
+ Please email any feedback to team@promptjoy.com.
76
+
77
+
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "promptjoy-ruby"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
@@ -0,0 +1,3 @@
1
+ module PromptjoyRuby
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "promptjoy-ruby/version"
4
+ require 'net/http'
5
+ require 'json'
6
+ require 'uri'
7
+ require 'logger'
8
+
9
+ module PromptjoyRuby
10
+ class Error < StandardError; end
11
+
12
+ class Client
13
+ def initialize(api_key = nil, logger: Logger.new(STDOUT))
14
+ @api_key = api_key
15
+ @logger = logger
16
+ end
17
+
18
+ def find_by_api_url(url, api_key: nil)
19
+ Api.new(api_key || @api_key, url, logger: @logger)
20
+ end
21
+ end
22
+
23
+ class Api
24
+ USER_AGENT = "PromptjoyRubyGem/#{PromptjoyRuby::VERSION}"
25
+
26
+ def initialize(api_key, url, logger: Logger.new(STDOUT))
27
+ @api_key = api_key
28
+ @url = url
29
+ @logger = logger
30
+ end
31
+
32
+ def call(api_data, client_ip = nil, referrer = nil)
33
+ uri = URI(@url)
34
+ http = Net::HTTP.new(uri.host, uri.port)
35
+
36
+ if uri.scheme == 'https'
37
+ http.use_ssl = true
38
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
39
+ end
40
+
41
+ @logger.debug "URI: #{uri}"
42
+ @logger.debug "API Data: #{api_data}"
43
+
44
+ request = Net::HTTP::Post.new(uri)
45
+
46
+ request['Authorization'] = "Bearer #{@api_key}"
47
+ request['Client-Ip'] = client_ip if client_ip
48
+ request['User-Agent'] = USER_AGENT
49
+ request['Referrer'] = referrer if referrer
50
+ request.body = api_data.to_json
51
+ request['Content-Type'] = 'application/json'
52
+
53
+ response = http.request(request)
54
+ handle_response(response)
55
+ end
56
+
57
+ private
58
+
59
+ def handle_response(response)
60
+ case response
61
+ when Net::HTTPSuccess
62
+ JSON.parse(response.body)
63
+ when Net::HTTPUnauthorized
64
+ raise Error.new("API call failed due to unauthorized access. Check your API key.")
65
+ else
66
+ raise Error.new("API call failed with HTTP #{response.code} #{response.message}")
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "lib/promptjoy-ruby/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "promptjoy-ruby"
5
+ spec.version = PromptjoyRuby::VERSION
6
+ spec.authors = ["PromptJoy Team"]
7
+ spec.email = ["team@promptjoy.com"]
8
+
9
+ spec.summary = "Official PromptJoy Ruby Gem."
10
+ spec.description = %q{The PromptJoy ruby gem provides a simple and efficient way to interact with the PromptJoy API in Ruby. It handles the API authentication, request formation, and response parsing, providing the users with an intuitive interface to make API calls and retrieve the data.}
11
+
12
+ spec.homepage = "https://promptjoy.com"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata = {
17
+ "homepage_uri" => "https://promptjoy.com",
18
+ "bug_tracker_uri" => "https://github.com/promptjoy/promptjoy-ruby/issues",
19
+ "documentation_uri" => "https://docs.promptjoy.com",
20
+ "changelog_uri" => "https://github.com/promptjoy/promptjoy-ruby/blob/main/Changes.md",
21
+ "source_code_uri" => "https://github.com/promptjoy/promptjoy-ruby",
22
+ "rubygems_mfa_required" => "true"
23
+ }
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features|.*\.gem$)/}) }
26
+
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Add rspec and webmock as development dependencies
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ spec.add_development_dependency "webmock", "~> 3.0"
34
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: promptjoy-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - PromptJoy Team
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description: The PromptJoy ruby gem provides a simple and efficient way to interact
42
+ with the PromptJoy API in Ruby. It handles the API authentication, request formation,
43
+ and response parsing, providing the users with an intuitive interface to make API
44
+ calls and retrieve the data.
45
+ email:
46
+ - team@promptjoy.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - ".rspec"
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - bin/console
59
+ - bin/setup
60
+ - lib/promptjoy-ruby.rb
61
+ - lib/promptjoy-ruby/version.rb
62
+ - promptjoy-ruby.gemspec
63
+ homepage: https://promptjoy.com
64
+ licenses:
65
+ - MIT
66
+ metadata:
67
+ homepage_uri: https://promptjoy.com
68
+ bug_tracker_uri: https://github.com/promptjoy/promptjoy-ruby/issues
69
+ documentation_uri: https://docs.promptjoy.com
70
+ changelog_uri: https://github.com/promptjoy/promptjoy-ruby/blob/main/Changes.md
71
+ source_code_uri: https://github.com/promptjoy/promptjoy-ruby
72
+ rubygems_mfa_required: 'true'
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 2.6.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.2.15
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Official PromptJoy Ruby Gem.
92
+ test_files: []