dev_ruby 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c72c665418cd3f98071b63f5192ca1b74bc1b0cb3805baf8bcb0908de56f5dc0
4
- data.tar.gz: 3634d40cf94496c311baaac15b82262d05c7a171eb1e72ebcd6db0287eb1da30
3
+ metadata.gz: c1c35c131f4d0749cf24f1cf2519f23d87f359e97f556da536143437edb75efe
4
+ data.tar.gz: 4e711b29631fbf72826f5926136500dfc4d45013dbf982781ed34dd79ec21622
5
5
  SHA512:
6
- metadata.gz: e9b600c9fbff1e4f974641774ea691153d6b177f7e6ba924895fd2f3ad581193a7e0374c586eef5317f51b8589df73ed2912605529a626ad91c9a5dfa484aad4
7
- data.tar.gz: 1ff3ba0012d7a8cc59cf0a8daf8fcb655befa2f197ceaceadb5bee7900e1b0aefc84bacf8df7deeb81c752f925ca4670c2fc7faba79d5a2c022df2572a61c5ca
6
+ metadata.gz: 1699373aeb06e55e340b8a82907ecf0ecba792644dcb5d100dddd63308b38f9d2f301ee7738707f9a0b64b10b68ca7636eb6f14a60cf23bb774fe65c86122f1e
7
+ data.tar.gz: c60c30f1ae27aee813c4cb7695f18985b96b7403fb7108c6965b08bb34b6e51ab7664eb0a0ba74cf0bbeeff0da2b19b080e36403cef559c5a6a8b1fe0b9fa1c8
data/Gemfile CHANGED
@@ -19,3 +19,6 @@ gem 'dry-monads', '~> 1.4'
19
19
 
20
20
  # Pretty print Ruby objects with proper indentation and colors [https://github.com/awesome-print/awesome_print]
21
21
  gem 'awesome_print'
22
+
23
+ # A mixin to add configuration functionality to your classes [https://github.com/dry-rb/dry-configurable]
24
+ gem 'dry-configurable', '~> 0.15.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dev_ruby (0.1.0)
4
+ dev_ruby (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,6 +9,9 @@ GEM
9
9
  ast (2.4.2)
10
10
  awesome_print (1.9.2)
11
11
  concurrent-ruby (1.1.10)
12
+ dry-configurable (0.15.0)
13
+ concurrent-ruby (~> 1.0)
14
+ dry-core (~> 0.6)
12
15
  dry-core (0.7.1)
13
16
  concurrent-ruby (~> 1.0)
14
17
  dry-monads (1.4.0)
@@ -47,6 +50,7 @@ PLATFORMS
47
50
  DEPENDENCIES
48
51
  awesome_print
49
52
  dev_ruby!
53
+ dry-configurable (~> 0.15.0)
50
54
  dry-monads (~> 1.4)
51
55
  faraday (~> 2.2)
52
56
  minitest (~> 5.0)
data/README.md CHANGED
@@ -11,7 +11,7 @@ Ruby bindings for DEV API
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'dev_ruby'
14
+ gem 'dev_ruby', github: 'nejdetkadir/dev-ruby', branch: 'main'
15
15
  ```
16
16
 
17
17
  And then execute:
@@ -22,8 +22,259 @@ Or install it yourself as:
22
22
 
23
23
  $ gem install dev_ruby
24
24
 
25
+ ## Configuration
26
+ ```ruby
27
+ DevRuby.configure do |config|
28
+ config.logger = ::Logger.new($stdout).tap { |d| d.level = Logger::DEBUG }
29
+ config.log_api_bodies = true
30
+ config.per_page = 20
31
+ end
32
+ ```
33
+
25
34
  ## Usage
26
- TODO: Write usage instructions here
35
+ To access the API, you'll need to create a DevRuby::Client and pass in your API key. You can find your API key at [https://developers.forem.com/api](https://developers.forem.com/api)
36
+
37
+ ```ruby
38
+ client = DevRuby::Client.new(api_key: ENV['DEV_API_KEY'])
39
+ ```
40
+ The client then gives you access to each of the resources.
41
+
42
+ ## Resources
43
+ The gem maps as closely as we can to the DEV API so you can easily convert API examples to gem code.
44
+
45
+ Responses are returning as objects like `DevRuby::Objects::Article` with using [dry-monads](https://github.com/dry-rb/dry-monads) gem for easly error handling. Having types like `DevRuby::Objects::Article` is handy for understanding what type of object you're working with. They're built using OpenStruct so you can easily access data in a Ruby-ish way.
46
+
47
+ ```ruby
48
+ # Sample request with dry-monads
49
+
50
+ client = DevRuby::Client.new(api_key: ENV['DEV_API_KEY'])
51
+
52
+ operation = client.articles.create(title: 'My Article',
53
+ body: 'This is my article')
54
+
55
+ if operation.success?
56
+ article = operation.success
57
+
58
+ puts 'Article created successfully'
59
+ puts "Article ID: #{article.id}"
60
+ end
61
+
62
+ if operation.failure?
63
+ errors = operation.failure
64
+
65
+ puts 'Article creation failed'
66
+ puts "Error: #{errors}"
67
+ end
68
+
69
+ operation.value! # Returns the article if successful or return error if not successful
70
+ ```
71
+
72
+ ## Pagination
73
+ Some endpoints return pages of results. The result object will have a data key to access the results, as well as metadata like next_page and prev_page for retrieving the next and previous pages. You may also specify the
74
+
75
+ ```ruby
76
+ collection = client.articles.published.value!
77
+ #=> DevRuby::Collection
78
+
79
+ collection.data
80
+ #=> [#<DevRuby::Objects::Article>, #<DevRuby::Objects::Article>]
81
+
82
+ collection.data.count
83
+ #=> 3
84
+
85
+ collection.next_page
86
+ #=> "3"
87
+
88
+ collection.prev_page
89
+ #=> "1"
90
+
91
+ # Retrieve the next page
92
+ client.articles.published(per_page: 100, page: collection.next_page)
93
+ #=> DevRuby::Collection
94
+ ```
95
+
96
+ ## Articles
97
+ ```ruby
98
+ # This endpoint allows the client to retrieve a list of articles.
99
+ # By default it will return featured, published articles ordered by descending popularity.
100
+ collection = client.articles.published.value! # per_page is optional, defaults to 20.
101
+ #=> DevRuby::Collection
102
+
103
+ # This endpoint allows the client to create a new article.
104
+ article = client.articles.create(title: 'Hello, World!',
105
+ published: true,
106
+ body_markdown: 'Hello DEV, this is my first post',
107
+ tags: %w[discuss help],
108
+ series: 'Hello series').value!
109
+ #=> DevRuby::Objects::Article
110
+
111
+ # This endpoint allows the client to retrieve a list of articles. ordered by descending publish date.
112
+ collection = client.articles.latest_published.value!
113
+ #=> DevRuby::Collection
114
+
115
+ # This endpoint allows the client to retrieve a single published article given its id.
116
+ article = client.articles.find('123456').value!
117
+ #=> DevRuby::Objects::Article
118
+
119
+ # This endpoint allows the client to update an existing article.
120
+ article = client.articles.update(id: '123456',
121
+ title: 'Hello, World!').value!
122
+ #=> DevRuby::Objects::Article
123
+
124
+ # This endpoint allows the client to retrieve a single published article given its path.
125
+ article = client.articles.find_by_path(username: 'nejdetkadir', slug: 'hello-world').value!
126
+ #=> DevRuby::Objects::Article
127
+
128
+ # This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.
129
+ # Published articles will be in reverse chronological publication order.
130
+ collection = client.articles.me.value!
131
+ #=> DevRuby::Collection
132
+
133
+ # This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.
134
+ # Published articles will be in reverse chronological publication order
135
+ collection = client.articles.me_published.value!
136
+ #=> DevRuby::Collection
137
+
138
+ # This endpoint allows the client to retrieve a list of unpublished articles on behalf of an authenticated user.
139
+ # Unpublished articles will be in reverse chronological creation order.
140
+ collection = client.articles.me_unpublished.value!
141
+ #=> DevRuby::Collection
142
+
143
+ # This endpoint allows the client to retrieve a list of all articles on behalf of an authenticated user.
144
+ # It will return both published and unpublished articles with pagination.
145
+ # Unpublished articles will be at the top of the list in reverse chronological creation order. Published articles will follow in reverse chronological publication order
146
+ collection = client.articles.me_all.value!
147
+ #=> DevRuby::Collection
148
+
149
+ # This endpoint allows the client to retrieve a list of articles that are uploaded with a video.
150
+ # It will only return published video articles ordered by descending popularity.
151
+ collection = client.articles.videos.value!
152
+ #=> DevRuby::Collection
153
+ ```
154
+
155
+ ## Comments
156
+ ```ruby
157
+ # This endpoint allows the client to retrieve all comments belonging to an article or podcast episode as threaded conversations.
158
+ # It will return the all top level comments with their nested comments as threads. See the format specification for further details.
159
+ collection = client.comments.all.value!
160
+ #=> DevRuby::Collection
161
+
162
+ # This endpoint allows the client to retrieve a comment as well as his descendants comments.
163
+ # It will return the required comment (the root) with its nested descendants as a thread.
164
+ # See the format specification for further details.
165
+ comment = client.comments.find('123456').value!
166
+ #=> DevRuby::Objects::Comment
167
+ ```
168
+
169
+ ## Follows
170
+ ```ruby
171
+ # This endpoint allows the client to retrieve a list of the tags they follow.
172
+ collection = client.follows.followed_tags.value!
173
+ #=> DevRuby::Collection
174
+ ```
175
+
176
+ ## Followers
177
+ ```ruby
178
+ # This endpoint allows the client to retrieve a list of the followers they have.
179
+ collection = client.followers.all.value!
180
+ #=> DevRuby::Collection
181
+ ```
182
+
183
+ ## Listings
184
+ ```ruby
185
+ # This endpoint allows the client to retrieve a list of listings.
186
+ # By default it will return published listings ordered by descending freshness.
187
+ collection = client.listings.published.value!
188
+ #=> DevRuby::Collection
189
+
190
+ # This endpoint allows the client to create a new listing.
191
+ # The user creating the listing or the organization on which behalf the user is creating for need to have enough credits for this operation to be successful. The server will prioritize the organization's credits over the user's credits.
192
+ listing = client.listings.create(title: 'ACME Conference',
193
+ body_markdown: 'Awesome conference',
194
+ category: 'cfp',
195
+ tags: %w[events]).value!
196
+ #=> DevRuby::Objects::Listing
197
+
198
+ # This endpoint allows the client to retrieve a list of listings belonging to the specified category.
199
+ # By default it will return published listings ordered by descending freshness.
200
+ collection = client.listings.published_by_category(category: 'cfp').value!
201
+ #=> DevRuby::Collection
202
+
203
+ # This endpoint allows the client to retrieve a single listing given its id.
204
+ # An unpublished listing is only accessible if authentication is supplied and it belongs to the authenticated user.
205
+ listing = client.listings.find('123456').value!
206
+ #=> DevRuby::Objects::Listing
207
+
208
+ # This endpoint allows the client to update an existing listing.
209
+ article = client.listings.update(id: '123456', action: 'bump').value!
210
+ #=> DevRuby::Objects::Listing
211
+ ```
212
+
213
+ ## Organizations
214
+ ```ruby
215
+ # This endpoint allows the client to retrieve a single organization by their username.
216
+ organization = client.organizations.find_by_username('nejdetkadir').value!
217
+ #=> DevRuby::Objects::Organization
218
+
219
+ # This endpoint allows the client to retrieve a list of users belonging to the organization
220
+ collection = client.organizations.all_users_by_username(username: 'nejdetkadir').value!
221
+ #=> DevRuby::Collection
222
+
223
+ # This endpoint allows the client to retrieve a list of listings belonging to the organization
224
+ collection = client.organizations.all_listings_by_username(username: 'nejdetkadir').value!
225
+ #=> DevRuby::Collection
226
+
227
+ # This endpoint allows the client to retrieve a list of Articles belonging to the organization
228
+ collection = client.organizations.all_articles_by_username(username: 'nejdetkadir').value!
229
+ #=> DevRuby::Collection
230
+ ```
231
+
232
+ ## Podcast Episodes
233
+ ```ruby
234
+ # This endpoint allows the client to retrieve a list of podcast episodes.
235
+ collection = client.podcast_episodes.published.value!
236
+ #=> DevRuby::Collection
237
+ ```
238
+
239
+ ## Readinglists
240
+ ```ruby
241
+ # This endpoint allows the client to retrieve a list of readinglist reactions along with the related article for the authenticated user.
242
+ # Reading list will be in reverse chronological order base on the creation of the reaction.
243
+ collection = client.readinglists.all.value!
244
+ #=> DevRuby::Collection
245
+ ```
246
+
247
+ ## Tags
248
+ ```ruby
249
+ # This endpoint allows the client to retrieve a list of tags that can be used to tag articles.
250
+ # It will return tags ordered by popularity.
251
+ collection = client.tags.all.value!
252
+ #=> DevRuby::Collection
253
+
254
+ # This endpoint allows the client to retrieve a list of the tags they follow.
255
+ collection = client.tags.followed_tags.value!
256
+ #=> DevRuby::Collection
257
+ ```
258
+
259
+ ## Users
260
+ ```ruby
261
+ # This endpoint allows the client to retrieve a list of published articles on behalf of an authenticated user.
262
+ user = client.users.me.value!
263
+ #=> DevRuby::Objects::User
264
+
265
+ # This endpoint allows the client to retrieve a single user, either by id or by the user's username
266
+ user = client.users.find('123456').value!
267
+ #=> DevRuby::Objects::User
268
+
269
+ invitation = client.users.invite_user(email: 'user@example.com', name: 'string').value!
270
+ #=> true
271
+ ```
272
+
273
+ ## Profile Images
274
+ ```ruby
275
+ profile_image = client.profile_images.find_by_username('nejdetkadir').value!
276
+ #=> DevRuby::Objects::ProfileImage
277
+ ```
27
278
 
28
279
  ## Development
29
280
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,29 +3,70 @@
3
3
  module DevRuby
4
4
  class Client
5
5
  BASE_URL = 'https://dev.to/api'
6
- API_KEY = 'api-key'
6
+ AUTHORIZATION_KEY = 'api-key'
7
7
 
8
8
  attr_reader :api_key, :adapter
9
9
 
10
10
  def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
11
11
  @api_key = api_key
12
12
  @adapter = adapter
13
-
14
- # Test stubs for requests
15
- @stubs = stubs
13
+ @stubs = stubs # Test stubs for requests
16
14
  end
17
15
 
18
16
  def articles
19
17
  DevRuby::Resources::ArticlesResource.new(self)
20
18
  end
21
19
 
20
+ def comments
21
+ DevRuby::Resources::CommentsResource.new(self)
22
+ end
23
+
24
+ def follows
25
+ DevRuby::Resources::FollowsResource.new(self)
26
+ end
27
+
28
+ def followers
29
+ DevRuby::Resources::FollowersResource.new(self)
30
+ end
31
+
32
+ def listings
33
+ DevRuby::Resources::ListingsResource.new(self)
34
+ end
35
+
36
+ def organizations
37
+ DevRuby::Resources::OrganizationsResource.new(self)
38
+ end
39
+
40
+ def podcast_episodes
41
+ DevRuby::Resources::PodcastEpisodesResource.new(self)
42
+ end
43
+
44
+ def readinglist
45
+ DevRuby::Resources::ReadinglistsResource.new(self)
46
+ end
47
+
48
+ def tags
49
+ DevRuby::Resources::TagsResource.new(self)
50
+ end
51
+
52
+ def users
53
+ DevRuby::Resources::UsersResource.new(self)
54
+ end
55
+
56
+ def profile_images
57
+ DevRuby::Resources::ProfileImagesResource.new(self)
58
+ end
59
+
60
+ # rubocop:disable Layout/LineLength
22
61
  def connection
23
62
  @connection ||= Faraday.new(BASE_URL) do |conn|
24
- conn.headers[API_KEY] = api_key
63
+ conn.headers[AUTHORIZATION_KEY] = api_key
25
64
  conn.request :json
26
65
  conn.response :json, content_type: 'application/json'
66
+ conn.response :logger, DevRuby.logger, body: true, bodies: { request: true, response: true } if DevRuby.log_api_bodies
27
67
  conn.adapter adapter, @stubs
28
68
  end
29
69
  end
70
+ # rubocop:enable Layout/LineLength
30
71
  end
31
72
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Comment < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Error < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Follower < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Listing < BaseObject
6
+ CATEGORIES = %w[
7
+ cfp forhire collabs education jobs mentors
8
+ products mentees forsale events misc
9
+ ].freeze
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Organization < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class PodcastEpisode < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class ProfileImage < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class Tag < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class User < BaseObject
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Objects
5
+ class VideoArticle < BaseObject
6
+ end
7
+ end
8
+ end
@@ -4,8 +4,6 @@
4
4
  module DevRuby
5
5
  module Resources
6
6
  class ArticlesResource < BaseResource
7
- attr_reader :client
8
-
9
7
  def published(**params)
10
8
  params = to_default_pagination_params(params)
11
9
 
@@ -62,7 +60,7 @@ module DevRuby
62
60
  end
63
61
  end
64
62
 
65
- def update(id, **body)
63
+ def update(id:, **body)
66
64
  response = put_request("articles/#{id}", body: { article: body })
67
65
 
68
66
  if Helpers.expected_response?(response, 200)
@@ -86,13 +84,17 @@ module DevRuby
86
84
  end
87
85
  end
88
86
 
89
- def me
87
+ def me(**params)
88
+ params = to_default_pagination_params(params)
89
+
90
90
  response = get_request('articles/me')
91
91
 
92
92
  if Helpers.expected_response?(response, 200)
93
- article = DevRuby::Objects::Article.new(response.body)
93
+ collection = Collection.from_response(response: response,
94
+ type: DevRuby::Objects::Article,
95
+ params: params)
94
96
 
95
- Success(article)
97
+ Success(collection)
96
98
  else
97
99
  Failure(error_parser(response))
98
100
  end
@@ -153,7 +155,7 @@ module DevRuby
153
155
 
154
156
  if Helpers.expected_response?(response, 200)
155
157
  collection = Collection.from_response(response: response,
156
- type: DevRuby::Objects::Article,
158
+ type: DevRuby::Objects::VideoArticle,
157
159
  params: params)
158
160
 
159
161
  Success(collection)
@@ -36,12 +36,12 @@ module DevRuby
36
36
  end
37
37
 
38
38
  def error_parser(response)
39
- OpenStruct.new(status: response.status, body: response.body)
39
+ DevRuby::Objects::Error.new(response.body)
40
40
  end
41
41
 
42
42
  def to_default_pagination_params(params)
43
43
  params[:page] ||= 1
44
- params[:per_page] ||= 20
44
+ params[:per_page] ||= DevRuby.per_page
45
45
  params
46
46
  end
47
47
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class CommentsResource < BaseResource
6
+ def all(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('comments', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Comment,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+
22
+ def find(id)
23
+ response = get_request("comments/#{id}")
24
+
25
+ if Helpers.expected_response?(response, 200)
26
+ comment = DevRuby::Objects::Comment.new(response.body)
27
+
28
+ Success(comment)
29
+ else
30
+ Failure(error_parser(response))
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class FollowersResource < BaseResource
6
+ def all(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('followers/users')
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Follower,
14
+ params: params)
15
+ Success(collection)
16
+ else
17
+ Failure(error_parser(response))
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class FollowsResource < BaseResource
6
+ def followed_tags(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('follows/tags', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Tag,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class ListingsResource < BaseResource
6
+ def published(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('listings', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Listing,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+
22
+ def create(**body)
23
+ response = post_request('listings', body: { listing: body })
24
+
25
+ if Helpers.expected_response?(response, 201)
26
+ listing = DevRuby::Objects::Listing.new(response.body)
27
+
28
+ Success(listing)
29
+ else
30
+ Failure(error_parser(response))
31
+ end
32
+ end
33
+
34
+ def published_by_category(category:, **params)
35
+ params = to_default_pagination_params(params)
36
+
37
+ response = get_request("listings/category/#{category}", params: params)
38
+
39
+ if Helpers.expected_response?(response, 200)
40
+ collection = Collection.from_response(response: response,
41
+ type: DevRuby::Objects::Listing,
42
+ params: params)
43
+
44
+ Success(collection)
45
+ else
46
+ Failure(error_parser(response))
47
+ end
48
+ end
49
+
50
+ def find(id)
51
+ response = get_request("listings/#{id}")
52
+
53
+ if Helpers.expected_response?(response, 200)
54
+ listing = DevRuby::Objects::Listing.new(response.body)
55
+
56
+ Success(listing)
57
+ else
58
+ Failure(error_parser(response))
59
+ end
60
+ end
61
+
62
+ def update(id:, **body)
63
+ response = put_request("listings/#{id}", body: { listing: body })
64
+
65
+ if Helpers.expected_response?(response, 200)
66
+ listing = DevRuby::Objects::Listing.new(response.body)
67
+
68
+ Success(listing)
69
+ else
70
+ Failure(error_parser(response))
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class OrganizationsResource < BaseResource
6
+ def find_by_username(username)
7
+ response = get_request("organizations/#{username}")
8
+
9
+ if Helpers.expected_response?(response, 200)
10
+ organization = DevRuby::Objects::Organization.new(response.body)
11
+
12
+ Success(organization)
13
+ else
14
+ Failure(error_parser(response))
15
+ end
16
+ end
17
+
18
+ def all_users_by_username(username:, **params)
19
+ params = to_default_pagination_params(params)
20
+
21
+ response = get_request("organizations/#{username}/users", params: params)
22
+
23
+ if Helpers.expected_response?(response, 200)
24
+ collection = Collection.from_response(response: response,
25
+ type: DevRuby::Objects::User,
26
+ params: params)
27
+
28
+ Success(collection)
29
+ else
30
+ Failure(error_parser(response))
31
+ end
32
+ end
33
+
34
+ def all_listings_by_username(username:, **params)
35
+ params = to_default_pagination_params(params)
36
+
37
+ response = get_request("organizations/#{username}/listings", params: params)
38
+
39
+ if Helpers.expected_response?(response, 200)
40
+ collection = Collection.from_response(response: response,
41
+ type: DevRuby::Objects::Listing,
42
+ params: params)
43
+
44
+ Success(collection)
45
+ else
46
+ Failure(error_parser(response))
47
+ end
48
+ end
49
+
50
+ def all_articles_by_username(username:, **params)
51
+ params = to_default_pagination_params(params)
52
+
53
+ response = get_request("organizations/#{username}/articles", params: params)
54
+
55
+ if Helpers.expected_response?(response, 200)
56
+ collection = Collection.from_response(response: response,
57
+ type: DevRuby::Objects::Article,
58
+ params: params)
59
+
60
+ Success(collection)
61
+ else
62
+ Failure(error_parser(response))
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class PodcastEpisodesResource < BaseResource
6
+ def published(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('podcast_episodes', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::PodcastEpisode,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class ProfileImagesResource < BaseResource
6
+ def find_by_username(username)
7
+ response = get_request("profile_images/#{username}")
8
+
9
+ if Helpers.expected_response?(response, 200)
10
+ profile_image = DevRuby::Objects::ProfileImage.new(response.body)
11
+
12
+ Success(profile_image)
13
+ else
14
+ Failure(error_parser(response))
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class ReadinglistsResource < BaseResource
6
+ def all(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('readinglist', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Article,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class TagsResource < BaseResource
6
+ def all(**params)
7
+ params = to_default_pagination_params(params)
8
+
9
+ response = get_request('tags', params: params)
10
+
11
+ if Helpers.expected_response?(response, 200)
12
+ collection = Collection.from_response(response: response,
13
+ type: DevRuby::Objects::Tag,
14
+ params: params)
15
+
16
+ Success(collection)
17
+ else
18
+ Failure(error_parser(response))
19
+ end
20
+ end
21
+
22
+ def followed_tags(**params)
23
+ params = to_default_pagination_params(params)
24
+
25
+ response = get_request('tags', params: params)
26
+
27
+ if Helpers.expected_response?(response, 200)
28
+ collection = Collection.from_response(response: response,
29
+ type: DevRuby::Objects::Tag,
30
+ params: params)
31
+
32
+ Success(collection)
33
+ else
34
+ Failure(error_parser(response))
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DevRuby
4
+ module Resources
5
+ class UsersResource < BaseResource
6
+ def me
7
+ response = get_request('users/me')
8
+
9
+ if Helpers.expected_response?(response, 200)
10
+ user = DevRuby::Objects::User.new(response.body)
11
+
12
+ Success(user)
13
+ else
14
+ Failure(error_parser(response))
15
+ end
16
+ end
17
+
18
+ def find(id)
19
+ response = get_request("users/#{id}")
20
+
21
+ if Helpers.expected_response?(response, 200)
22
+ user = DevRuby::Objects::User.new(response.body)
23
+
24
+ Success(user)
25
+ else
26
+ Failure(error_parser(response))
27
+ end
28
+ end
29
+
30
+ def invite_user(**body)
31
+ response = post_request('admin/users', body: body)
32
+
33
+ if Helpers.expected_response?(response, 200)
34
+ Success(response.body)
35
+ else
36
+ Failure(error_parser(response))
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevRuby
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/dev_ruby.rb CHANGED
@@ -1,20 +1,43 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'faraday'
4
+ require 'dry-configurable'
4
5
  require 'awesome_print'
5
6
  require_relative 'dev_ruby/version'
6
7
 
7
8
  module DevRuby
9
+ extend Dry::Configurable
10
+
11
+ setting :logger, default: ::Logger.new($stdout), reader: true
12
+ setting :log_api_bodies, default: false, reader: true
13
+ setting :per_page, default: 20, reader: true
14
+
8
15
  require_relative 'dev_ruby/helpers'
9
16
  require_relative 'dev_ruby/error'
10
17
  require_relative 'dev_ruby/client'
11
18
  require_relative 'dev_ruby/collection'
12
-
13
- # Resources
14
19
  require_relative 'dev_ruby/resources/base_resource'
15
20
  require_relative 'dev_ruby/resources/articles_resource'
16
-
17
- # Objects
21
+ require_relative 'dev_ruby/resources/comments_resource'
22
+ require_relative 'dev_ruby/resources/follows_resource'
23
+ require_relative 'dev_ruby/resources/followers_resource'
24
+ require_relative 'dev_ruby/resources/listings_resource'
25
+ require_relative 'dev_ruby/resources/organizations_resource'
26
+ require_relative 'dev_ruby/resources/podcast_episodes_resource'
27
+ require_relative 'dev_ruby/resources/readinglists_resource'
28
+ require_relative 'dev_ruby/resources/users_resource'
29
+ require_relative 'dev_ruby/resources/tags_resource'
30
+ require_relative 'dev_ruby/resources/profile_images_resource'
18
31
  require_relative 'dev_ruby/objects/base_object'
19
32
  require_relative 'dev_ruby/objects/article'
33
+ require_relative 'dev_ruby/objects/video_article'
34
+ require_relative 'dev_ruby/objects/comment'
35
+ require_relative 'dev_ruby/objects/error'
36
+ require_relative 'dev_ruby/objects/tag'
37
+ require_relative 'dev_ruby/objects/follower'
38
+ require_relative 'dev_ruby/objects/listing'
39
+ require_relative 'dev_ruby/objects/organization'
40
+ require_relative 'dev_ruby/objects/user'
41
+ require_relative 'dev_ruby/objects/podcast_episode'
42
+ require_relative 'dev_ruby/objects/profile_image'
20
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dev_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - nejdetkadir
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-15 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby bindings for DEV API
14
14
  email:
@@ -33,8 +33,28 @@ files:
33
33
  - lib/dev_ruby/helpers.rb
34
34
  - lib/dev_ruby/objects/article.rb
35
35
  - lib/dev_ruby/objects/base_object.rb
36
+ - lib/dev_ruby/objects/comment.rb
37
+ - lib/dev_ruby/objects/error.rb
38
+ - lib/dev_ruby/objects/follower.rb
39
+ - lib/dev_ruby/objects/listing.rb
40
+ - lib/dev_ruby/objects/organization.rb
41
+ - lib/dev_ruby/objects/podcast_episode.rb
42
+ - lib/dev_ruby/objects/profile_image.rb
43
+ - lib/dev_ruby/objects/tag.rb
44
+ - lib/dev_ruby/objects/user.rb
45
+ - lib/dev_ruby/objects/video_article.rb
36
46
  - lib/dev_ruby/resources/articles_resource.rb
37
47
  - lib/dev_ruby/resources/base_resource.rb
48
+ - lib/dev_ruby/resources/comments_resource.rb
49
+ - lib/dev_ruby/resources/followers_resource.rb
50
+ - lib/dev_ruby/resources/follows_resource.rb
51
+ - lib/dev_ruby/resources/listings_resource.rb
52
+ - lib/dev_ruby/resources/organizations_resource.rb
53
+ - lib/dev_ruby/resources/podcast_episodes_resource.rb
54
+ - lib/dev_ruby/resources/profile_images_resource.rb
55
+ - lib/dev_ruby/resources/readinglists_resource.rb
56
+ - lib/dev_ruby/resources/tags_resource.rb
57
+ - lib/dev_ruby/resources/users_resource.rb
38
58
  - lib/dev_ruby/version.rb
39
59
  - sig/dev_ruby.rbs
40
60
  homepage: https://github.com/nejdetkadir/dev-ruby