Class: DevRuby::Resources::ArticlesResource

Inherits:
BaseResource show all
Defined in:
lib/dev_ruby/resources/articles_resource.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from DevRuby::Resources::BaseResource

Instance Method Details

#create(**body) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dev_ruby/resources/articles_resource.rb', line 23

def create(**body)
  response = post_request('articles', body: { article: body })

  if Helpers.expected_response?(response, 201)
    article = DevRuby::Objects::Article.new(response.body)

    Success(article)
  else
    Failure(error_parser(response))
  end
end

#find(id) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dev_ruby/resources/articles_resource.rb', line 51

def find(id)
  response = get_request("articles/#{id}")

  if Helpers.expected_response?(response, 200)
    article = DevRuby::Objects::Article.new(response.body)

    Success(article)
  else
    Failure(error_parser(response))
  end
end

#find_by_path(username:, slug:) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/dev_ruby/resources/articles_resource.rb', line 75

def find_by_path(username:, slug:)
  response = get_request("articles/#{username}/#{slug}")

  if Helpers.expected_response?(response, 200)
    article = DevRuby::Objects::Article.new(response.body)

    Success(article)
  else
    Failure(error_parser(response))
  end
end

#latest_published(**params) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dev_ruby/resources/articles_resource.rb', line 35

def latest_published(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles/latest', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#me(**params) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/dev_ruby/resources/articles_resource.rb', line 87

def me(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles/me')

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#me_all(**params) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/dev_ruby/resources/articles_resource.rb', line 135

def me_all(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles/me/all', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#me_published(**params) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dev_ruby/resources/articles_resource.rb', line 103

def me_published(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles/me/published', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#me_unpublished(**params) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/dev_ruby/resources/articles_resource.rb', line 119

def me_unpublished(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles/me/unpublished', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#published(**params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/dev_ruby/resources/articles_resource.rb', line 7

def published(**params)
  params = to_default_pagination_params(params)

  response = get_request('articles', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::Article,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end

#update(id:, **body) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/dev_ruby/resources/articles_resource.rb', line 63

def update(id:, **body)
  response = put_request("articles/#{id}", body: { article: body })

  if Helpers.expected_response?(response, 200)
    article = DevRuby::Objects::Article.new(response.body)

    Success(article)
  else
    Failure(error_parser(response))
  end
end

#videos(**params) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/dev_ruby/resources/articles_resource.rb', line 151

def videos(**params)
  params = to_default_pagination_params(params)

  response = get_request('videos', params: params)

  if Helpers.expected_response?(response, 200)
    collection = Collection.from_response(response: response,
                                          type: DevRuby::Objects::VideoArticle,
                                          params: params)

    Success(collection)
  else
    Failure(error_parser(response))
  end
end