Class: GhostRb::Client
- Inherits:
-
Object
- Object
- GhostRb::Client
- Defined in:
- lib/ghost_rb/client.rb
Overview
Instance Attribute Summary collapse
- #base_url ⇒ Object readonly
- #client_id ⇒ Object readonly
- #client_secret ⇒ Object readonly
- #default_query ⇒ Object readonly
Instance Method Summary collapse
- #get(endpoint, query) ⇒ Object
-
#initialize(base_url, client_id, client_secret) ⇒ Client
constructor
A new instance of Client.
- #posts ⇒ Object
- #tags ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(base_url, client_id, client_secret) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ghost_rb/client.rb', line 13 def initialize(base_url, client_id, client_secret) @base_url = URI.join(base_url, 'ghost/', 'api/', 'v0.1/') @client_id = client_id @client_secret = client_secret @http = HTTPClient.new(base_url: @base_url) @default_query = Support::HashWithIndifferentAccess.new( client_id: @client_id, client_secret: @client_secret ) end |
Instance Attribute Details
#base_url ⇒ Object (readonly)
11 12 13 |
# File 'lib/ghost_rb/client.rb', line 11 def base_url @base_url end |
#client_id ⇒ Object (readonly)
11 12 13 |
# File 'lib/ghost_rb/client.rb', line 11 def client_id @client_id end |
#client_secret ⇒ Object (readonly)
11 12 13 |
# File 'lib/ghost_rb/client.rb', line 11 def client_secret @client_secret end |
#default_query ⇒ Object (readonly)
11 12 13 |
# File 'lib/ghost_rb/client.rb', line 11 def default_query @default_query end |
Instance Method Details
#get(endpoint, query) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/ghost_rb/client.rb', line 36 def get(endpoint, query) response = @http.get(endpoint, query, {}, follow_redirect: true) content = Support::HashWithIndifferentAccess.new( JSON.parse(response.body) ) [response.status_code, content] end |
#posts ⇒ Object
24 25 26 |
# File 'lib/ghost_rb/client.rb', line 24 def posts Controllers::PostsController.new(self) end |
#tags ⇒ Object
28 29 30 |
# File 'lib/ghost_rb/client.rb', line 28 def Controllers::TagsController.new(self) end |
#users ⇒ Object
32 33 34 |
# File 'lib/ghost_rb/client.rb', line 32 def users Controllers::UsersController.new(self) end |