Class: GhostRb::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ghost_rb/client.rb

Overview

Author:

  • Rene Hernandez

Since:

  • 0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, client_id, client_secret) ⇒ Client

Returns a new instance of Client.

Since:

  • 0.1



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_urlObject (readonly)

Since:

  • 0.1



11
12
13
# File 'lib/ghost_rb/client.rb', line 11

def base_url
  @base_url
end

#client_idObject (readonly)

Since:

  • 0.1



11
12
13
# File 'lib/ghost_rb/client.rb', line 11

def client_id
  @client_id
end

#client_secretObject (readonly)

Since:

  • 0.1



11
12
13
# File 'lib/ghost_rb/client.rb', line 11

def client_secret
  @client_secret
end

#default_queryObject (readonly)

Since:

  • 0.1



11
12
13
# File 'lib/ghost_rb/client.rb', line 11

def default_query
  @default_query
end

Instance Method Details

#get(endpoint, query) ⇒ Object

Since:

  • 0.1



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

#postsObject

Since:

  • 0.1



24
25
26
# File 'lib/ghost_rb/client.rb', line 24

def posts
  Controllers::PostsController.new(self)
end

#tagsObject

Since:

  • 0.1



28
29
30
# File 'lib/ghost_rb/client.rb', line 28

def tags
  Controllers::TagsController.new(self)
end

#usersObject

Since:

  • 0.1



32
33
34
# File 'lib/ghost_rb/client.rb', line 32

def users
  Controllers::UsersController.new(self)
end