Class: DevRuby::Client
- Inherits:
-
Object
- Object
- DevRuby::Client
- Defined in:
- lib/dev_ruby/client.rb
Constant Summary collapse
- BASE_URL =
'https://dev.to/api'- AUTHORIZATION_KEY =
'api-key'
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #articles ⇒ Object
- #comments ⇒ Object
-
#connection ⇒ Object
rubocop:disable Layout/LineLength.
- #followers ⇒ Object
- #follows ⇒ Object
-
#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #listings ⇒ Object
- #organizations ⇒ Object
- #podcast_episodes ⇒ Object
- #profile_images ⇒ Object
- #readinglist ⇒ Object
- #tags ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/dev_ruby/client.rb', line 10 def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key @adapter = adapter @stubs = stubs # Test stubs for requests end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
8 9 10 |
# File 'lib/dev_ruby/client.rb', line 8 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/dev_ruby/client.rb', line 8 def api_key @api_key end |
Instance Method Details
#articles ⇒ Object
16 17 18 |
# File 'lib/dev_ruby/client.rb', line 16 def articles DevRuby::Resources::ArticlesResource.new(self) end |
#comments ⇒ Object
20 21 22 |
# File 'lib/dev_ruby/client.rb', line 20 def comments DevRuby::Resources::CommentsResource.new(self) end |
#connection ⇒ Object
rubocop:disable Layout/LineLength
61 62 63 64 65 66 67 68 69 |
# File 'lib/dev_ruby/client.rb', line 61 def connection @connection ||= Faraday.new(BASE_URL) do |conn| conn.headers[AUTHORIZATION_KEY] = api_key conn.request :json conn.response :json, content_type: 'application/json' conn.response :logger, DevRuby.logger, body: true, bodies: { request: true, response: true } if DevRuby.log_api_bodies conn.adapter adapter, @stubs end end |
#followers ⇒ Object
28 29 30 |
# File 'lib/dev_ruby/client.rb', line 28 def followers DevRuby::Resources::FollowersResource.new(self) end |
#follows ⇒ Object
24 25 26 |
# File 'lib/dev_ruby/client.rb', line 24 def follows DevRuby::Resources::FollowsResource.new(self) end |
#listings ⇒ Object
32 33 34 |
# File 'lib/dev_ruby/client.rb', line 32 def listings DevRuby::Resources::ListingsResource.new(self) end |
#organizations ⇒ Object
36 37 38 |
# File 'lib/dev_ruby/client.rb', line 36 def organizations DevRuby::Resources::OrganizationsResource.new(self) end |
#podcast_episodes ⇒ Object
40 41 42 |
# File 'lib/dev_ruby/client.rb', line 40 def podcast_episodes DevRuby::Resources::PodcastEpisodesResource.new(self) end |
#profile_images ⇒ Object
56 57 58 |
# File 'lib/dev_ruby/client.rb', line 56 def profile_images DevRuby::Resources::ProfileImagesResource.new(self) end |
#readinglist ⇒ Object
44 45 46 |
# File 'lib/dev_ruby/client.rb', line 44 def readinglist DevRuby::Resources::ReadinglistsResource.new(self) end |
#tags ⇒ Object
48 49 50 |
# File 'lib/dev_ruby/client.rb', line 48 def DevRuby::Resources::TagsResource.new(self) end |
#users ⇒ Object
52 53 54 |
# File 'lib/dev_ruby/client.rb', line 52 def users DevRuby::Resources::UsersResource.new(self) end |