Class: Ghost::Client
- Inherits:
-
Object
- Object
- Ghost::Client
- Defined in:
- lib/ghost/client.rb
Instance Method Summary collapse
- #delete(url) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(config:, authenticator:) ⇒ Client
constructor
A new instance of Client.
- #post(url, body = {}) ⇒ Object
- #put(url, body = {}) ⇒ Object
- #upload(url, file_path, ref: nil) ⇒ Object
Constructor Details
#initialize(config:, authenticator:) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/ghost/client.rb', line 9 def initialize(config:, authenticator:) @config = config @authenticator = authenticator @connection = build_connection end |
Instance Method Details
#delete(url) ⇒ Object
27 28 29 |
# File 'lib/ghost/client.rb', line 27 def delete(url) request(:delete, url) end |
#get(url, params = {}) ⇒ Object
15 16 17 |
# File 'lib/ghost/client.rb', line 15 def get(url, params = {}) request(:get, url, params) end |
#post(url, body = {}) ⇒ Object
19 20 21 |
# File 'lib/ghost/client.rb', line 19 def post(url, body = {}) request(:post, url, body) end |
#put(url, body = {}) ⇒ Object
23 24 25 |
# File 'lib/ghost/client.rb', line 23 def put(url, body = {}) request(:put, url, body) end |
#upload(url, file_path, ref: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ghost/client.rb', line 31 def upload(url, file_path, ref: nil) mime = detect_mime(file_path) payload = { file: Faraday::Multipart::FilePart.new(file_path, mime) } payload[:ref] = ref if ref response = @connection.post(url) do |req| @authenticator.apply(req) req.headers["Accept-Version"] = @config.version req.body = payload end handle_response(response) end |