Class: BlogApi::Client
- Inherits:
-
Object
- Object
- BlogApi::Client
- Defined in:
- lib/blog_api/client.rb
Defined Under Namespace
Classes: RequestError
Constant Summary collapse
- DEFAULT_URL =
'https://k-blog0130.herokuapp.com/api/v2/'
Instance Attribute Summary collapse
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #categories ⇒ Object
- #featured_posts ⇒ Object
- #get(path, options: { format: :plain }) ⇒ Object
-
#initialize(base_url = DEFAULT_URL) ⇒ Client
constructor
A new instance of Client.
- #post(post_id) ⇒ Object
- #posts ⇒ Object
- #tags ⇒ Object
Constructor Details
#initialize(base_url = DEFAULT_URL) ⇒ Client
Returns a new instance of Client.
10 11 12 |
# File 'lib/blog_api/client.rb', line 10 def initialize(base_url = DEFAULT_URL) @base_url = base_url end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/blog_api/client.rb', line 8 def base_url @base_url end |
Instance Method Details
#categories ⇒ Object
23 24 25 |
# File 'lib/blog_api/client.rb', line 23 def categories get('categories').parsed_body end |
#featured_posts ⇒ Object
35 36 37 |
# File 'lib/blog_api/client.rb', line 35 def featured_posts get("featured_posts").parsed_body end |
#get(path, options: { format: :plain }) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/blog_api/client.rb', line 14 def get(path, options: { format: :plain }) url = "#{base_url}/#{path}" result = HTTParty.get(url, ) raise RequestError unless result.response.code == '200' BlogApi::Response.new(result) end |
#post(post_id) ⇒ Object
31 32 33 |
# File 'lib/blog_api/client.rb', line 31 def post(post_id) get("posts/#{post_id}").parsed_body end |
#posts ⇒ Object
27 28 29 |
# File 'lib/blog_api/client.rb', line 27 def posts get('posts').parsed_body end |
#tags ⇒ Object
39 40 41 |
# File 'lib/blog_api/client.rb', line 39 def get("tags").parsed_body end |