Class: Micropub::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(post_type, attrs = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/micropub/client.rb', line 8

def initialize(post_type, attrs={})
  @post_type = post_type
  @token     = attrs[:token]
end

Instance Attribute Details

#post_typeObject (readonly)

Returns the value of attribute post_type.



7
8
9
# File 'lib/micropub/client.rb', line 7

def post_type
  @post_type
end

#tokenObject (readonly)

Returns the value of attribute token.



7
8
9
# File 'lib/micropub/client.rb', line 7

def token
  @token
end

Instance Method Details

#headersObject



21
22
23
# File 'lib/micropub/client.rb', line 21

def headers
  {"Authorization" => "Bearer #{token}"}
end

#hostObject



33
34
35
36
37
# File 'lib/micropub/client.rb', line 33

def host
  # ENV is temp to hardcode the host before
  # the hs router is hooked up.
  ENV["PUBLISHER_HOST"] || Micropub.configuration.me
end

#post(content) ⇒ Object



13
14
15
# File 'lib/micropub/client.rb', line 13

def post(content)
  request HTTPClient.post(uri, content, headers)
end

#publisherObject



25
26
27
# File 'lib/micropub/client.rb', line 25

def publisher
  post_type.pluralize
end

#request(response) ⇒ Object



17
18
19
# File 'lib/micropub/client.rb', line 17

def request(response)
  Micropub::Response.new(response)
end

#uriObject



29
30
31
# File 'lib/micropub/client.rb', line 29

def uri
  "#{host}/#{publisher}"
end