Class: Envato::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/envato/client.rb

Constant Summary collapse

BASE_URL =
"https://api.envato.com"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/envato/client.rb', line 9

def initialize(token:, adapter: Faraday.default_adapter, stubs: nil)
  @token = token
  @adapter = adapter
  @stubs = stubs # Test stubs for requests
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/envato/client.rb', line 7

def adapter
  @adapter
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/envato/client.rb', line 7

def token
  @token
end

Instance Method Details

#bookmarksObject



35
36
37
# File 'lib/envato/client.rb', line 35

def bookmarks
  BookmarksResource.new(self)
end

#connectionObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/envato/client.rb', line 43

def connection
  @connection ||= Faraday.new(BASE_URL) do |conn|
    conn.request :authorization, :Bearer, token
    conn.request :json
    conn.request :url_encoded

    conn.response :json, content_type: "application/json"

    conn.adapter adapter, @stubs
  end
end

#itemObject



39
40
41
# File 'lib/envato/client.rb', line 39

def item
  ItemResource.new(self)
end

#marketObject



27
28
29
# File 'lib/envato/client.rb', line 27

def market
  MarketResource.new(self)
end

#marketsObject



31
32
33
# File 'lib/envato/client.rb', line 31

def markets
  MarketsResource.new(self)
end

#searchObject



23
24
25
# File 'lib/envato/client.rb', line 23

def search
  SearchResource.new(self)
end

#userObject



15
16
17
# File 'lib/envato/client.rb', line 15

def user
  UserResource.new(self)
end

#usersObject



19
20
21
# File 'lib/envato/client.rb', line 19

def users
  UsersResource.new(self)
end