Class: Micropub::Client
- Inherits:
-
Object
- Object
- Micropub::Client
- Defined in:
- lib/micropub/client.rb
Instance Attribute Summary collapse
-
#post_type ⇒ Object
readonly
Returns the value of attribute post_type.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #headers ⇒ Object
- #host ⇒ Object
-
#initialize(post_type, attrs = {}) ⇒ Client
constructor
A new instance of Client.
- #post(content) ⇒ Object
- #publisher ⇒ Object
- #request(response) ⇒ Object
- #uri ⇒ Object
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_type ⇒ Object (readonly)
Returns the value of attribute post_type.
7 8 9 |
# File 'lib/micropub/client.rb', line 7 def post_type @post_type end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
7 8 9 |
# File 'lib/micropub/client.rb', line 7 def token @token end |
Instance Method Details
#headers ⇒ Object
21 22 23 |
# File 'lib/micropub/client.rb', line 21 def headers {"Authorization" => "Bearer #{token}"} end |
#host ⇒ Object
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 |
#publisher ⇒ Object
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 |
#uri ⇒ Object
29 30 31 |
# File 'lib/micropub/client.rb', line 29 def uri "#{host}/#{publisher}" end |