Module: Pili::RPC
- Defined in:
- lib/pili/rpc.rb
Class Method Summary collapse
- .delete(credentials, url) ⇒ Object
- .get(credentials, url) ⇒ Object
- .post(credentials, url, body) ⇒ Object
Class Method Details
.delete(credentials, url) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/pili/rpc.rb', line 57 def delete(credentials, url) url = Config.api_base_url + url = { :url => url, :method => "DELETE" } encoded_sign = Credentials.sign(credentials.secret_key, Credentials.generate_signature()) headers = { "Authorization" => "Qiniu #{credentials.access_key}:#{encoded_sign}" } response = HTTParty.delete(url, :headers => headers) if response.code == 204 response.parsed_response else raise ResponseError.new("Pili API Request Error", response) end end |
.get(credentials, url) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/pili/rpc.rb', line 8 def get(credentials, url) url = Config.api_base_url + url = { :url => url, :method => "GET" } encoded_sign = Credentials.sign(credentials.secret_key, Credentials.generate_signature()) headers = { "Authorization" => "Qiniu #{credentials.access_key}:#{encoded_sign}" } response = HTTParty.get(url, :headers => headers) if response.code == 200 response.parsed_response else raise ResponseError.new("Pili API Request Error", response) end end |
.post(credentials, url, body) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/pili/rpc.rb', line 30 def post(credentials, url, body) url = Config.api_base_url + url = { :url => url, :content_type => "application/json", :method => "POST", :body => body } encoded_sign = Credentials.sign(credentials.secret_key, Credentials.generate_signature()) headers = { "Authorization" => "Qiniu #{credentials.access_key}:#{encoded_sign}", "Content-Type" => "application/json" } response = HTTParty.post(url, :headers => headers, :body => body.to_json) if response.code == 200 response.parsed_response else raise ResponseError.new("Pili API Request Error", response) end end |