class BlogApi::Client
Constants
- DEFAULT_URL
Attributes
base_url[R]
Public Class Methods
new(base_url = DEFAULT_URL)
click to toggle source
# File lib/blog_api/client.rb, line 10 def initialize(base_url = DEFAULT_URL) @base_url = base_url end
Public Instance Methods
categories()
click to toggle source
# File lib/blog_api/client.rb, line 23 def categories get('categories').parsed_body end
featured_posts()
click to toggle source
# File lib/blog_api/client.rb, line 35 def featured_posts get("featured_posts").parsed_body end
get(path, options: { format: :plain })
click to toggle source
# File lib/blog_api/client.rb, line 14 def get(path, options: { format: :plain }) url = "#{base_url}/#{path}" result = HTTParty.get(url, options) raise RequestError unless result.response.code == '200' BlogApi::Response.new(result) end
post(post_id)
click to toggle source
# File lib/blog_api/client.rb, line 31 def post(post_id) get("posts/#{post_id}").parsed_body end
posts()
click to toggle source
# File lib/blog_api/client.rb, line 27 def posts get('posts').parsed_body end