Class: RightSignature::Connection
- Inherits:
-
Object
- Object
- RightSignature::Connection
- Defined in:
- lib/rightsignature/connection.rb
Class Method Summary collapse
- .get(url, params = {}, headers = {}) ⇒ Object
- .post(url, body = {}, headers = {}) ⇒ Object
- .site ⇒ Object
Class Method Details
.get(url, params = {}, headers = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rightsignature/connection.rb', line 12 def get(url, params={}, headers={}) RightSignature::check_credentials if RightSignature::has_api_token? = {} [:headers] = headers [:query] = params RightSignature::TokenConnection.request(:get, url, ).parsed_response else unless params.empty? url = "#{url}?#{params.sort.map{|param| URI.escape("#{param[0]}=#{param[1]}")}.join('&')}" end res = RightSignature::OauthConnection.request(:get, url, headers) MultiXml.parse(res.body) end end |
.post(url, body = {}, headers = {}) ⇒ Object
29 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/rightsignature/connection.rb', line 29 def post(url, body={}, headers={}) RightSignature::check_credentials if RightSignature::has_api_token? = {} [:headers] = headers [:body] = XmlFu.xml(body) res = RightSignature::TokenConnection.request(:post, url, ) unless res.success? puts res.body raise RightSignature::ResponseError.new(res) end res.parsed_response else res = RightSignature::OauthConnection.request(:post, url, XmlFu.xml(body), headers) unless res.is_a? Net::HTTPSuccess puts res.body raise RightSignature::ResponseError.new(res) end MultiXml.parse(res.body) end end |
.site ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/rightsignature/connection.rb', line 4 def site if RightSignature::has_api_token? RightSignature::TokenConnection.base_uri else RightSignature::OauthConnection.oauth_consumer.site end end |