Class: NftmakerApi::Client
- Inherits:
-
Object
- Object
- NftmakerApi::Client
show all
- Defined in:
- lib/nftmaker_api/client.rb
Defined Under Namespace
Classes: Nfts, Project, Projects, Reservation, Reservations
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
7
8
9
10
11
12
13
14
|
# File 'lib/nftmaker_api/client.rb', line 7
def initialize(options = {})
@configuration = OpenStruct.new(
NftmakerApi.configuration.to_h.merge(options)
)
@api_key = @configuration.api_key
@host = @configuration.host
end
|
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
5
6
7
|
# File 'lib/nftmaker_api/client.rb', line 5
def api_key
@api_key
end
|
#configuration ⇒ Object
Returns the value of attribute configuration.
5
6
7
|
# File 'lib/nftmaker_api/client.rb', line 5
def configuration
@configuration
end
|
#host ⇒ Object
Returns the value of attribute host.
5
6
7
|
# File 'lib/nftmaker_api/client.rb', line 5
def host
@host
end
|
#last_response ⇒ Object
Returns the value of attribute last_response.
5
6
7
|
# File 'lib/nftmaker_api/client.rb', line 5
def last_response
@last_response
end
|
Instance Method Details
#get(endpoint) ⇒ Object
36
37
38
|
# File 'lib/nftmaker_api/client.rb', line 36
def get(endpoint)
@last_response = Response.new(http_client.get endpoint)
end
|
#http_client ⇒ Object
48
49
50
51
52
|
# File 'lib/nftmaker_api/client.rb', line 48
def http_client
@http_client ||= Faraday.new(url: host, headers: {'Content-Type' => 'application/json'}) do |f|
f.adapter configuration.http_adapter
end
end
|
#nfts ⇒ Object
24
25
26
|
# File 'lib/nftmaker_api/client.rb', line 24
def nfts
Nfts.new(self)
end
|
#post(endpoint, body) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/nftmaker_api/client.rb', line 40
def post(endpoint, body)
response = http_client.post(endpoint) do |req|
req.body = Oj.dump(body)
end
@last_response = Response.new(response)
end
|
#project(id) ⇒ Object
20
21
22
|
# File 'lib/nftmaker_api/client.rb', line 20
def project(id)
Project.new(self, id)
end
|
#projects ⇒ Object
16
17
18
|
# File 'lib/nftmaker_api/client.rb', line 16
def projects
Projects.new(self)
end
|
#reservation(project_id:, address:) ⇒ Object
32
33
34
|
# File 'lib/nftmaker_api/client.rb', line 32
def reservation(project_id:, address:)
Reservation.new(self, project_id: project_id, address: address)
end
|
#reservations(project_id:) ⇒ Object
28
29
30
|
# File 'lib/nftmaker_api/client.rb', line 28
def reservations(project_id:)
Reservations.new(self, project_id: project_id)
end
|