Class: SBF::Client::BlogPostEndpoint
Constant Summary
collapse
- FILTER_BY_AUTHOR =
'author'.freeze
- FILTER_BY_CATEGORY =
'category'.freeze
- FILTER_BY_TERM =
'filter_term'.freeze
- FILTER_BY_TAG =
'tag'.freeze
Instance Attribute Summary
#orig_target_class
Instance Method Summary
collapse
-
#base_uri ⇒ Object
-
#find_by_author(author, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
-
#find_by_category(category, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
-
#find_by_tag(tag, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
-
#find_by_term(term, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
-
#get(slug) ⇒ Object
#aggregate, #create, #delete, #find, #find_first, #initialize, #save, #update
Instance Method Details
#base_uri ⇒ Object
12
13
14
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 12
def base_uri
"/#{SBF::Client::Api::VERSION}/blog_post"
end
|
#find_by_author(author, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 40
def find_by_author(author, order = {}, limit = 10, offset = 0, show_hidden = true)
raise SBF::Client::Error, 'Must provide author for the query' if author.empty?
filter = {}
filter[:type] = FILTER_BY_AUTHOR
filter[:term] = author
filter[:show_hidden] = show_hidden
find(filter, order, limit, offset)
end
|
#find_by_category(category, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 51
def find_by_category(category, order = {}, limit = 10, offset = 0, show_hidden = true)
raise SBF::Client::Error, 'Must provide category for the query' if category.empty?
filter = {}
filter[:type] = FILTER_BY_CATEGORY
filter[:term] = category
filter[:show_hidden] = show_hidden
find(filter, order, limit, offset)
end
|
#find_by_tag(tag, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 62
def find_by_tag(tag, order = {}, limit = 10, offset = 0, show_hidden = true)
raise SBF::Client::Error, 'Must provide tag for the query' if tag.empty?
filter = {}
filter[:type] = FILTER_BY_TAG
filter[:term] = tag
filter[:show_hidden] = show_hidden
find(filter, order, limit, offset)
end
|
#find_by_term(term, order = {}, limit = 10, offset = 0, show_hidden = true) ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 30
def find_by_term(term, order = {}, limit = 10, offset = 0, show_hidden = true)
filter = {}
filter[:type] = FILTER_BY_TERM
filter[:term] = term unless term.empty?
filter[:show_hidden] = show_hidden
find(filter, order, limit, offset)
end
|
#get(slug) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/stbaldricks/endpoints/blog_post.rb', line 16
def get(slug)
response = SBF::Client::Api::Request.get_request("#{base_uri}/get/#{slug}")
if ok?(response)
hydrated_entity(response, {}, nil)
elsif response.code == 404
nil
else
parsed_response_body = JSON.parse(response.body).symbolize!
error = SBF::Client::ErrorEntity.new(parsed_response_body)
SBF::Client::Api::Response.new(http_code: response.code, data: parsed_response_body[:data], error: error)
end
end
|