nftmaker_api 0.1.0

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: 7ed4a8b49bcb2bacacbc032d1fa3ab8dfde2d350f4e1a98196b88e776ef1492f
4
+ data.tar.gz: a0b785bef14d2a0305fd8b161fa5d69f38460604b540a7939c9d800d32c394eb
5
+ SHA512:
6
+ metadata.gz: 8052ddbee95d2133f94d2ac6983cac268debd2303c726a581ae5baaf5eceb2e058208cf0741f2adbd85c7afce390907c56ef2a64dffcb34012064e9f331ecc94
7
+ data.tar.gz: 341940e422281d82d7f64a5ede43b8711acf5ea11b99ac7a1e51e4601907a0b8f3264a3a40e458993c653c281c8bf35a3dc6f95c9bbe8e9e748cca759c954afd
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 lacepool
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,160 @@
1
+ # NftmakerApi
2
+
3
+ A Ruby client for the https://nft-maker.io/pro API.
4
+
5
+ It aims to support all API methods. The intuitive query methods allow to easily call the API endpoints.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nftmaker_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nftmaker_api
22
+
23
+ ## Configuration
24
+
25
+ The configuration options can be set by using the `configure` block
26
+
27
+ ```ruby
28
+ NftmakerApi.configure do |config|
29
+ config.api_key = ENV.fetch('NFT_MAKER_PRO_API_KEY')
30
+ end
31
+ ```
32
+
33
+ Alternatively, you can configure the settings by passing a hash of options to an instance like so
34
+
35
+ ```ruby
36
+ client = NftmakerApi.new api_key: "xyz",
37
+ http_adapter: :typheous
38
+ ```
39
+
40
+ The following is the list of available configuration options
41
+
42
+ ```ruby
43
+ api_key # The API key provided by nft-maker.io
44
+ http_adapter # The http client used for performing requests. Default :net_http
45
+ host # The API endpoint. Default: https://api.nft-maker.io
46
+ ```
47
+
48
+ ## 1 Usage
49
+
50
+ To start using the gem, you first create a new client instance
51
+
52
+ ```ruby
53
+ client = NftmakerApi.new
54
+ ```
55
+
56
+ and then you call the methods for the API endpoints.
57
+
58
+ ### 1.1 Endpoints
59
+
60
+ List all projects
61
+
62
+ ```ruby
63
+ client.projects.list
64
+ ```
65
+
66
+ Show metrics for a project
67
+
68
+ ```ruby
69
+ client.project(1634).metrics
70
+ ```
71
+
72
+ List all NFTs for a project
73
+
74
+ ```ruby
75
+ client.project(1634).nfts.list # all
76
+ client.project(1634).nfts.sold # only sold
77
+ client.project(1634).nfts.free # only free
78
+ client.project(1634).nfts.reserved # only reserved
79
+ ```
80
+
81
+ Create a new project
82
+
83
+ ```ruby
84
+ client.projects.create(name: "Foo", policy_expires: true, policy_locks_at: Time.now.advance(months: 6), address_expires_in: 10)
85
+ ```
86
+
87
+ Reserve NFT(s) from a project
88
+
89
+ ```ruby
90
+ client.project(1634).reservations.create(nft_count: 1, lovelace: 10_000000) # Reserve a random NFT
91
+ client.project(1634).reservations.create(nft_id: 123, nft_count: 1, lovelace: 10_000000) # Reserve a specific NFT
92
+ ```
93
+
94
+ Check / Cancel a reservation
95
+
96
+ ```ruby
97
+ client.project(1634).reservation("addr1...").check
98
+ client.project(1634).reservation("addr1...").cancel
99
+ ```
100
+
101
+ ## 2 Response Handling
102
+
103
+ Responses are wrapped into a `NftmakerApi::Response` object. The main reason is to allow direct access to the parsed JSON response body.
104
+
105
+ Sidenote: The JSON body is parsed using [Oj](https://github.com/ohler55/oj) which is a C implementation, hence much faster than [JSON from Ruby's Standard Library](https://ruby-doc.org/stdlib-3.0.2/libdoc/json/rdoc/JSON.html).
106
+
107
+
108
+
109
+ ```ruby
110
+ client.projects.list.to_h
111
+ # => [{"id"=>123, "projectname" => "Foo", ...}, ...]
112
+ ```
113
+
114
+ Access the original faraday response object
115
+
116
+ ```ruby
117
+ client.projects.list.original_response
118
+ ```
119
+
120
+ ### 2.1 Errors
121
+
122
+ Check if the request was successful or returned an error
123
+
124
+ ```ruby
125
+ client.projects.list.success?
126
+ client.projects.list.error?
127
+ ```
128
+
129
+ Response errors are always `NftmakerApi::Error` objects.
130
+
131
+ ```ruby
132
+ client.projects.list.error
133
+ ```
134
+
135
+ Show error message including status code, status phrase and the actual error message from the API
136
+
137
+ ```ruby
138
+ client.projects.list.error.full_message
139
+ ```
140
+
141
+ Show status code
142
+
143
+ ```ruby
144
+ client.projects.list.error.status
145
+ ```
146
+
147
+ Show error message returned from the API
148
+
149
+ ```ruby
150
+ client.projects.list.error.reason
151
+ ```
152
+
153
+ ## 3 Contributing
154
+
155
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lacepool/nftmaker_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
156
+
157
+
158
+ ## 4 License
159
+
160
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,25 @@
1
+ module NftmakerApi
2
+ class Client::Nfts
3
+ def initialize(client, project_id: nil)
4
+ @client = client
5
+ @project_id = project_id
6
+ end
7
+
8
+ def list(state: :all)
9
+ @client.get "GetNfts/#{@client.api_key}/#{@project_id}/#{state}"
10
+ end
11
+ alias_method :all, :list
12
+
13
+ def free
14
+ list(state: :free)
15
+ end
16
+
17
+ def reserved
18
+ list(state: :reserved)
19
+ end
20
+
21
+ def sold
22
+ list(state: :sold)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module NftmakerApi
2
+ class Client::Project
3
+ def initialize(client, id)
4
+ @client = client
5
+ @id = id
6
+ end
7
+
8
+ def metrics
9
+ @client.get "GetCounts/#{@client.api_key}/#{@id}"
10
+ end
11
+
12
+ def nfts
13
+ NftmakerApi::Client::Nfts.new(@client, project_id: @id)
14
+ end
15
+
16
+ def reservations
17
+ NftmakerApi::Client::Reservations.new(@client, project_id: @id)
18
+ end
19
+
20
+ def reservation(address)
21
+ NftmakerApi::Client::Reservation.new(@client, project_id: @id, address: address)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ module NftmakerApi
2
+ class Client::Projects
3
+ def initialize(client)
4
+ @client = client
5
+ end
6
+
7
+ def create(name:, policy_expires: true, policy_locks_at: Time.now.advance(months: 6), address_expires_in: 10)
8
+ body = {projectname: name, maxNftSupply: 1, policyExpires: policy_expires, addressExpiretime: address_expires_in}
9
+ body.merge!({ policyLocksDateTime: policy_locks_at.iso8601 }) if policy_expires
10
+
11
+ @client.post "/CreateProject/#{@client.api_key}", body.to_json
12
+ end
13
+
14
+ def list
15
+ @client.get "ListProjects/#{@client.api_key}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module NftmakerApi
2
+ class Client::Reservation
3
+ def initialize(client, project_id:, address:)
4
+ @client = client
5
+ @project_id = project_id
6
+ @address = address
7
+ end
8
+
9
+ def check
10
+ @client.get "CheckAddress/#{@client.api_key}/#{@project_id}/#{@address}"
11
+ end
12
+
13
+ def cancel
14
+ @client.get "CancelAddressReservation/#{@client.api_key}/#{@project_id}/#{@address}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module NftmakerApi
2
+ class Client::Reservations
3
+ def initialize(client, project_id:)
4
+ @client = client
5
+ @project_id = project_id
6
+ end
7
+
8
+ def create(nft_id: nil, nft_count:, lovelace:)
9
+ if nft_id.blank?
10
+ endpoint = "GetAddressForRandomNftSale/#{@client.api_key}/#{@project_id}/#{nft_count}/#{lovelace}"
11
+ else
12
+ endpoint = "GetAddressForSpecificNftSale/#{@client.api_key}/#{@project_id}/#{nft_id}/#{nft_count}/#{lovelace}"
13
+ end
14
+
15
+ @client.get endpoint
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "response"
2
+
3
+ module NftmakerApi
4
+ class Client
5
+ attr_reader :configuration, :api_key, :host, :last_response
6
+
7
+ def initialize(options = {})
8
+ @configuration = OpenStruct.new(
9
+ NftmakerApi.configuration.to_h.merge(options)
10
+ )
11
+
12
+ @api_key = @configuration.api_key
13
+ @host = @configuration.host
14
+ end
15
+
16
+ def projects
17
+ Projects.new(self)
18
+ end
19
+
20
+ def project(id)
21
+ Project.new(self, id)
22
+ end
23
+
24
+ def nfts
25
+ Nfts.new(self)
26
+ end
27
+
28
+ def reservations(project_id:)
29
+ Reservations.new(self, project_id: project_id)
30
+ end
31
+
32
+ def reservation(project_id:, address:)
33
+ Reservation.new(self, project_id: project_id, address: address)
34
+ end
35
+
36
+ def get(endpoint)
37
+ @last_response = Response.new(http_client.get endpoint)
38
+ end
39
+
40
+ def post(endpoint, body)
41
+ response = http_client.post(endpoint) do |req|
42
+ req.body = Oj.dump(body)
43
+ end
44
+
45
+ @last_response = Response.new(response)
46
+ end
47
+
48
+ def http_client
49
+ @http_client ||= Faraday.new(url: host, headers: {'Content-Type' => 'application/json'}) do |f|
50
+ f.adapter configuration.http_adapter
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,24 @@
1
+ module NftmakerApi
2
+ class << self
3
+ def configuration
4
+ @configuration ||= OpenStruct.new(configuration_defaults)
5
+ end
6
+
7
+ def configuration_defaults
8
+ {
9
+ api_key: nil,
10
+ host: "https://api.nft-maker.io",
11
+ http_adapter: Faraday.default_adapter
12
+ }
13
+ end
14
+
15
+ def configure
16
+ yield(configuration)
17
+ end
18
+
19
+ def new(options = {})
20
+ Client.new(options)
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,24 @@
1
+ module NftmakerApi
2
+ class Error
3
+ def initialize(response)
4
+ @response = response
5
+ end
6
+
7
+ def to_s
8
+ ["#{status} #{status_phrase}", reason].compact.join(", ")
9
+ end
10
+ alias_method :full_message, :to_s
11
+
12
+ def status
13
+ @response.original.status
14
+ end
15
+
16
+ def status_phrase
17
+ @response.original.reason_phrase
18
+ end
19
+
20
+ def reason
21
+ @response.to_h.fetch("errorMessage") { nil }
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,29 @@
1
+ require_relative "error"
2
+
3
+ module NftmakerApi
4
+ class Response
5
+ attr_reader :original_response
6
+ alias_method :original, :original_response
7
+
8
+ def initialize(response)
9
+ @original_response = response
10
+ end
11
+
12
+ def parsed
13
+ @parsed = Oj.load(@original_response.body) || {}
14
+ end
15
+ alias_method :to_h, :parsed
16
+
17
+ def success?
18
+ @original_response.status == 200
19
+ end
20
+
21
+ def error?
22
+ !success?
23
+ end
24
+
25
+ def error
26
+ @error ||= success? ? nil : Error.new(self)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module NftmakerApi
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "faraday"
2
+ require "oj"
3
+
4
+ require_relative "nftmaker_api/version"
5
+ require_relative "nftmaker_api/configuration"
6
+
7
+ require_relative "nftmaker_api/client"
8
+ require_relative "nftmaker_api/client/project"
9
+ require_relative "nftmaker_api/client/projects"
10
+ require_relative "nftmaker_api/client/nfts"
11
+ require_relative "nftmaker_api/client/reservations"
12
+ require_relative "nftmaker_api/client/reservation"
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nftmaker_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - lacepool
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.10'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.10'
61
+ description: Ruby client that supports all of the nft-maker.io PRO API methods.
62
+ email:
63
+ - hello@lacepool.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - LICENSE.txt
68
+ - README.md
69
+ files:
70
+ - LICENSE.txt
71
+ - README.md
72
+ - lib/nftmaker_api.rb
73
+ - lib/nftmaker_api/client.rb
74
+ - lib/nftmaker_api/client/nfts.rb
75
+ - lib/nftmaker_api/client/project.rb
76
+ - lib/nftmaker_api/client/projects.rb
77
+ - lib/nftmaker_api/client/reservation.rb
78
+ - lib/nftmaker_api/client/reservations.rb
79
+ - lib/nftmaker_api/configuration.rb
80
+ - lib/nftmaker_api/error.rb
81
+ - lib/nftmaker_api/response.rb
82
+ - lib/nftmaker_api/version.rb
83
+ homepage: https://github.com/lacepool
84
+ licenses:
85
+ - MIT
86
+ metadata:
87
+ homepage_uri: https://github.com/lacepool
88
+ source_code_uri: https://github.com/lacepool/nftmaker_api
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: 2.3.0
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubygems_version: 3.2.28
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Ruby client for the nft-maker.io PRO API
108
+ test_files: []