Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
stgeneral committed Feb 21, 2024
1 parent 2c428d0 commit 02c693e
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 34 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FUNC_LIVE_TOKEN=
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FUNC_LIVE_TOKEN=
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
/spec/reports/
/tmp/

# rspec failure tracking
.env.*local
.rspec_status
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
AllCops:
TargetRubyVersion: 3.0

Style/Documentation:
Enabled: false

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ source "https://rubygems.org"
# Specify your gem's dependencies in func_live.gemspec
gemspec

gem "dotenv"
gem "rake", "~> 13.0"

gem "rspec", "~> 3.0"

gem "rubocop", "~> 1.21"
70 changes: 70 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
PATH
remote: .
specs:
func_live (0.1.0)
httparty

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
diff-lcs (1.5.0)
dotenv (3.0.2)
httparty (0.21.0)
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
json (2.6.3)
language_server-protocol (3.17.0.3)
mini_mime (1.1.5)
multi_xml (0.6.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
regexp_parser (2.9.0)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.54.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.4.2)

PLATFORMS
ruby
x86_64-darwin-22

DEPENDENCIES
dotenv
func_live!
rake (~> 13.0)
rspec (~> 3.0)
rubocop (~> 1.21)

BUNDLED WITH
2.5.6
71 changes: 60 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,67 @@
# FuncLive
# func(live)

TODO: Delete this and the text below, and describe your gem

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/func_live`. To experiment with that code, run `bin/console` for an interactive prompt.
This gem allows you to call functions available on https://func.live.

## Installation

TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.

Install the gem and add to the application's Gemfile by executing:
Install the gem and add to the application's `Gemfile` by executing:

$ bundle add func_live

Or add one of these lines to your application's `Gemfile` manually:

```ruby
# version released to RubyGems (recommended)
gem 'func_live'

$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
# or latest version from the repository
gem 'func_live', git: 'https://github.com/ergoserv/func_live'
# or from a specific branch of the GitHub repository
gem 'func_live', git: 'https://github.com/ergoserv/func_live', branch: 'develop'
# or from a local path (for development and testing purposes)
gem 'func_live', path: '../func_live'
```

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
$ gem install func_live

### Get and set the token

You can get your token at https://tokens.wakeflow.io.

Set token in environment variable `ENV["FUNC_LIVE_TOKEN"]`
or in code using the `FuncLive.token` writer:

```ruby
FuncLive.token = 'your_func_token'
```

## Usage

TODO: Write usage instructions here
There are many functions available on https://www.func.live,
the code snippet below demonstrates the usage of several of them.

```ruby
# Generate UUID - https://www.func.live/functions/uuid
FuncLive.("uuid")
# => "09ccfa6a-805e-46f5-ae4d-790988bec443"

# Get currency exchange rate for USD to EUR - https://www.func.live/functions/usdToEur
FuncLive.("usdToEur", 100)
# => 92.44

# Translate text to another language - https://www.func.live/functions/translate
FuncLive.(:translate, { text: "Hello World!", to: "FR" })
# => "Bonjour le monde!"

# Access OpenAI's GPT API with single line of code - https://www.func.live/functions/askGPT
FuncLive.(:askGPT, "Who are you?")
# => "I am a language model AI developed by OpenAI, created to assist and interact with users in generating human-like text based on the prompts given to me. How can I assist you today?"
```

You can browse all available functions at https://www.func.live/functions.

## Development

Expand All @@ -28,12 +71,18 @@ To install this gem onto your local machine, run `bundle exec rake install`. To

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/func_live. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/func_live/blob/master/CODE_OF_CONDUCT.md).
Bug reports and pull requests are welcome on GitHub at https://github.com/ergoserv/func_live. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ergoserv/func_live/blob/master/CODE_OF_CONDUCT.md).

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).

## Code of Conduct

Everyone interacting in the FuncLive project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/func_live/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in the FuncLive project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ergoserv/func_live/blob/master/CODE_OF_CONDUCT.md).

---

This gem was created and is maintained by [ErgoServ](https://www.ergoserv.com).

If you like what you see and would like to hire us or join us, [get in touch](https://www.ergoserv.com)!
4 changes: 2 additions & 2 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
require "bundler/setup"
require "func_live"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
require "dotenv"
Dotenv.load(".env.development.local", ".env.local", ".env.development", ".env")

require "irb"
IRB.start(__FILE__)
18 changes: 7 additions & 11 deletions func_live.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ Gem::Specification.new do |spec|
spec.authors = ["Dmitry Babenko"]
spec.email = ["[email protected]"]

spec.summary = "TODO: Write a short summary, because RubyGems requires one."
spec.description = "TODO: Write a longer description or delete this line."
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.summary = "fund(live)"
spec.description = "Allows you to import and call the functions on www.func.live."
spec.homepage = "https://www.func.live/"
spec.license = "MIT"
spec.required_ruby_version = ">= 3.0.0"

spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
Expand All @@ -32,9 +32,5 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

# Uncomment to register a new dependency of your gem
# spec.add_dependency "example-gem", "~> 1.0"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
spec.add_dependency "httparty"
end
24 changes: 23 additions & 1 deletion lib/func_live.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
# frozen_string_literal: true

require_relative "func_live/client"
require_relative "func_live/version"

module FuncLive
class Error < StandardError; end
# Your code goes here...

class << self
def token=(token) # rubocop:disable Style/TrivialAccessors
@token = token
end

def token
@token || ENV["FUNC_LIVE_TOKEN"]
end

def client
@client ||= FuncLive::Client.new(token)
end

def call(function_name, input = nil)
response = client.functions(function_name, input)

raise FuncLive::Error, response["error"] if response["success"] == false

response["output"]
end
end
end
27 changes: 27 additions & 0 deletions lib/func_live/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require "httparty"

module FuncLive
class Client
include HTTParty

base_uri "https://api.func.live"

def initialize(token)
@headers = {
"Content-Type" => "application/json",
"Authorization" => "Bearer #{token}"
}
end

def functions(function_name, input = nil)
body = { input: input }
self.class.post(
"/functions/#{function_name}",
headers: @headers,
body: body.to_json
)
end
end
end
4 changes: 0 additions & 4 deletions spec/func_live_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,4 @@
it "has a version number" do
expect(FuncLive::VERSION).not_to be nil
end

it "does something useful" do
expect(false).to eq(true)
end
end
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
require "func_live"

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.expect_with :rspec do |c|
Expand Down

0 comments on commit 02c693e

Please sign in to comment.