midjourney-ruby 0.1.1 → 0.2.0

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: 727ce777e01b7a609b901f0eeb3b27c2f0568eb9f27c126a5e31391202afd8c4
4
- data.tar.gz: dd12224e8cd69ceaf548221db086f3b009456aa594a30fe438786f111e0a0c42
3
+ metadata.gz: 2e648fd2e9826785943bab6a582fca4da21ae4358bf76cd80554b84f25e6df23
4
+ data.tar.gz: 2e3c6ad1067d655703e40e0b30b2a73c30e0812d9408f4303275253b8a62c68d
5
5
  SHA512:
6
- metadata.gz: 93b06c02f6ece38ef9fa4847d89b540ea8a08c5e519867349be534028ec725442b39608a975b387d713d2a6d21dfc73e9ecd36139563f6b265e8189d7d12c5ae
7
- data.tar.gz: 9047f70dd745f3a996ff9d7b74a8f4b6e470f7da664e97c83ab53765042d014ca0fda4964360c56f667e0c34d005ba8bf68923ae08492822063c145cbc94be93
6
+ metadata.gz: 487bb6c38f6ed7dc77ad490d02720b2f24d60129bc3c644a4cad178e285c12269e7fc212dac12ad6e5f9b553e0ba8fd6e99bd8b823e94df00d483c0ceb056fb7
7
+ data.tar.gz: 2819dadc88926ab1aad5d30bfbd331bd65fb0258103768d1dbf8f436865df0d993b94d005b43bf71c6ea7b6746a4e0ecf37ca301902ccc4168aab5f9d157a438
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Midjourney
4
+ module API
5
+ #
6
+ # Discord API Gateway using RestClient
7
+ #
8
+ class Gateway
9
+ BASE_URL = 'https://discord.com/api/v9'
10
+
11
+ attr_reader :token, :channel_id
12
+
13
+ def initialize(token:, channel_id:)
14
+ @token = token
15
+ @channel_id = channel_id
16
+ end
17
+
18
+ def read_messages(limit = 50)
19
+ get_request("#{BASE_URL}/channels/#{channel_id}/messages?limit=#{limit}")
20
+ end
21
+
22
+ def send_message(message)
23
+ post_request("#{BASE_URL}/channels/#{channel_id}/messages", message_payload(message))
24
+ end
25
+
26
+ def send_imagine(prompt)
27
+ post_request("#{BASE_URL}/interactions", imagine_payload(prompt))
28
+ end
29
+
30
+ private
31
+
32
+ def get_request(url)
33
+ JSON.parse RestClient.get(url, headers).body
34
+ rescue RestClient::ExceptionWithResponse => e
35
+ puts "Error sending message: #{e.response.body}"
36
+ end
37
+
38
+ def post_request(url, payload)
39
+ RestClient.post(url, payload, headers)
40
+ rescue RestClient::ExceptionWithResponse => e
41
+ puts "Error sending message: #{e.response.body}"
42
+ end
43
+
44
+ def imagine_payload(prompt) # rubocop:disable Metrics/MethodLength
45
+ {
46
+ type: 2,
47
+ application_id: '936929561302675456',
48
+ guild_id: '1158081328068165704',
49
+ channel_id: channel_id,
50
+ session_id: '939307d50a643c3d8cfcf4e756063e3b',
51
+ data: {
52
+ version: '1118961510123847772',
53
+ id: '938956540159881230',
54
+ name: 'imagine',
55
+ type: 1,
56
+ options: [
57
+ {
58
+ type: 3,
59
+ name: 'prompt',
60
+ value: prompt
61
+ }
62
+ ],
63
+ application_command: {
64
+ id: '938956540159881230',
65
+ application_id: '936929561302675456',
66
+ version: '1118961510123847772',
67
+ default_member_permissions: nil,
68
+ type: 1,
69
+ nsfw: false,
70
+ name: 'imagine',
71
+ description: 'Create images with Midjourney',
72
+ dm_permission: true,
73
+ contexts: [0, 1, 2],
74
+ integration_types: [0],
75
+ options: [
76
+ {
77
+ type: 3,
78
+ name: 'prompt',
79
+ description: 'The prompt to imagine',
80
+ required: true
81
+ }
82
+ ]
83
+ },
84
+ attachments: []
85
+ }
86
+ }.to_json
87
+ end
88
+
89
+ def message_payload(message)
90
+ {
91
+ content: message,
92
+ flags: 0,
93
+ mobile_network_type: 'unknown',
94
+ tts: false
95
+ }.to_json
96
+ end
97
+
98
+ def headers
99
+ @headers ||= {
100
+ 'Authorization' => token,
101
+ 'Accept' => 'application/json',
102
+ 'Content-Type' => 'application/json'
103
+ }
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Midjourney
4
+ module API
5
+ #
6
+ # Midjourney Imagine Module
7
+ #
8
+ module Imagine
9
+ def imagine(prompt)
10
+ api.send_imagine(prompt)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Midjourney
4
+ module API
5
+ #
6
+ # Midjourney Read Messages Module
7
+ #
8
+ module Messages
9
+ def read_messages(limit = 50)
10
+ api.read_messages(limit)
11
+ end
12
+
13
+ def send_message(message)
14
+ api.send_message(message)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Midjourney
2
+ #
3
+ # This class is used to store the configuration of the gem.
4
+ #
5
+ class Configuration
6
+ attr_accessor :discord_user_token, :discord_channel_id
7
+
8
+ def initialize
9
+ @discord_user_token = nil
10
+ @discord_channel_id = nil
11
+ end
12
+ end
13
+ end
data/lib/midjourney.rb ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'pry-byebug'
5
+ require 'rainbow'
6
+ require 'rake'
7
+ require 'rest-client'
8
+
9
+ require_relative 'midjourney/configuration'
10
+ require_relative 'midjourney/api/gateway'
11
+ require_relative 'midjourney/api/imagine'
12
+ require_relative 'midjourney/api/messages'
13
+
14
+ #
15
+ # Midjourney Ruby Client
16
+ #
17
+ module Midjourney
18
+ VERSION = '0.2.0'
19
+
20
+ class Error < StandardError; end
21
+
22
+ extend API::Imagine
23
+ extend API::Messages
24
+
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.config
30
+ yield(configuration)
31
+ end
32
+
33
+ def self.api
34
+ @api ||= API::Gateway.new(token: discord_user_token, channel_id: discord_channel_id)
35
+ end
36
+
37
+ def self.discord_user_token
38
+ configuration.discord_user_token
39
+ end
40
+
41
+ def self.discord_channel_id
42
+ configuration.discord_channel_id
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :midjourney do
4
+ desc 'Install Midjourney Ruby Client'
5
+ task install: :environment do
6
+ return :ok unless defined?(Rails)
7
+
8
+ initializer_content = <<~RUBY
9
+ # frozen_string_literal: true
10
+
11
+ #
12
+ # Take a look at https://github.com/leom806/midjourney-ruby for more information.
13
+ #
14
+ Midjourney.config do |config|
15
+ # Fetch from an environment variable or fetch from Rails credentials if
16
+ # you're using Rails 5.2+ and have credentials set up.
17
+
18
+ config.discord_user_token = ENV['DISCORD_USER_TOKEN']
19
+ config.discord_channel_id = ENV['DISCORD_CHANNEL_ID']
20
+ end
21
+ RUBY
22
+
23
+ initializer_path = Rails.root.join('config', 'initializers', 'midjourney.rb')
24
+
25
+ if File.exist?(initializer_path)
26
+ puts "\n #{Rainbow('Midjourney Ruby').purple} is already installed."
27
+ else
28
+ File.open(initializer_path, 'w') { |f| f.write(initializer_content) }
29
+ puts "\n #{Rainbow('Midjourney Ruby').purple} has been installed! 🎉"
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: midjourney-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonardo Momente
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-29 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.2'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.2'
11
+ date: 2023-10-01 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: This is a Ruby client for Midjourney that allows you to use its main
28
14
  products via their Discord API.
29
15
  email:
@@ -32,18 +18,17 @@ executables: []
32
18
  extensions: []
33
19
  extra_rdoc_files: []
34
20
  files:
35
- - ".rspec"
36
- - Gemfile
37
- - LICENSE.txt
38
- - README.md
39
- - Rakefile
40
- - lib/midjourney/ruby.rb
41
- - lib/midjourney/ruby/version.rb
42
- - sig/midjourney/ruby.rbs
21
+ - lib/midjourney.rb
22
+ - lib/midjourney/api/gateway.rb
23
+ - lib/midjourney/api/imagine.rb
24
+ - lib/midjourney/api/messages.rb
25
+ - lib/midjourney/configuration.rb
26
+ - lib/tasks/install.rb
43
27
  homepage: https://github.com/leom806/midjourney-ruby
44
28
  licenses:
45
29
  - MIT
46
30
  metadata:
31
+ allowed_push_host: https://rubygems.org
47
32
  homepage_uri: https://github.com/leom806/midjourney-ruby
48
33
  source_code_uri: https://github.com/leom806/midjourney-ruby
49
34
  changelog_uri: https://github.com/leom806/midjourney-ruby/blob/main/CHANGELOG.md
@@ -65,5 +50,5 @@ requirements: []
65
50
  rubygems_version: 3.4.10
66
51
  signing_key:
67
52
  specification_version: 4
68
- summary: Ruby client for Midjourney.
53
+ summary: Ruby client for Midjourney
69
54
  test_files: []
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/Gemfile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in midjourney-ruby.gemspec
6
- gemspec
7
-
8
- gem "rake", "~> 13.0"
9
-
10
- gem "rspec", "~> 3.0"
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023 Leonardo Momente
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 DELETED
@@ -1,37 +0,0 @@
1
- # Midjourney Ruby
2
-
3
- Midjourney is an awesome tool that brings great value to products.
4
- This gem was created to facilitate Ruby and also Rails applications to use all services of Midjourney directly.
5
-
6
- Keep in mind that you need to have a Midjourney account to use this gem, checkout [Midjourney](https://midjourney.com) for more information.
7
-
8
- ## Installation
9
-
10
- Add the following to your Gemfile:
11
-
12
- ```shell
13
- gem "midjourney-ruby"
14
- ```
15
-
16
- Run `bundle install`.
17
-
18
- That's it. You are now ready to go!
19
-
20
- ## Usage
21
-
22
- ### Imagine
23
-
24
- ## Development
25
-
26
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
-
28
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
-
30
- ## Contributing
31
-
32
- Bug reports and pull requests are welcome on GitHub at [Open an Issue](https://github.com/leom806/midjourney-ruby).
33
-
34
- ## License
35
-
36
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
37
- Feel free to use it and contribute.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Midjourney
4
- module Ruby
5
- VERSION = "0.1.1"
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "ruby/version"
4
-
5
- module Midjourney
6
- module Ruby
7
- class Error < StandardError; end
8
- # Your code goes here...
9
- end
10
- end
@@ -1,6 +0,0 @@
1
- module Midjourney
2
- module Ruby
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
- end
6
- end