Class: Rosemary::OauthClient

Inherits:
Client
  • Object
show all
Defined in:
lib/rosemary/oauth_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_token) ⇒ OauthClient

Returns a new instance of OauthClient.

Parameters:

  • access_token (OAuth::AccessToken)

    the access token to be used for write access.



8
9
10
# File 'lib/rosemary/oauth_client.rb', line 8

def initialize(access_token)
  @access_token = access_token
end

Instance Attribute Details

#access_tokenOAuth::AccessToken (readonly)

The access token to be used for all write access

Returns:

  • (OAuth::AccessToken)


5
6
7
# File 'lib/rosemary/oauth_client.rb', line 5

def access_token
  @access_token
end

Instance Method Details

#delete(url, options = {}, header = {}) ⇒ Object

Execute a signed OAuth DELETE request.

Unfortunately the OSM API requires to send an XML representation of the Element to be delete in the body of the request. The OAuth library does not support sending any information in the request body. If you know a workaround please fork and improve.

Raises:



35
36
37
38
39
# File 'lib/rosemary/oauth_client.rb', line 35

def delete(url, options={}, header={})
  raise NotImplemented.new("Delete with Oauth and OSM is not supported")
  # body = options[:body]
  # access_token.delete(url, {'Content-Type' => 'application/xml' })
end

#get(url, header = {}) ⇒ Object

Execute a signed OAuth GET request.

Parameters:

  • url (String)

    the url to be requested

  • header (Hash) (defaults to: {})

    optional header attributes



15
16
17
# File 'lib/rosemary/oauth_client.rb', line 15

def get(url, header={})
  access_token.get(url, {'Content-Type' => 'application/xml' })
end

#post(url, options = {}, header = {}) ⇒ Object

Execute a signed OAuth POST request.

Parameters:

  • url (String)

    the url to be requested

  • options (Hash) (defaults to: {})

    optional option attributes

  • header (Hash) (defaults to: {})

    optional header attributes



45
46
47
48
# File 'lib/rosemary/oauth_client.rb', line 45

def post(url, options={}, header={})
  body = options[:body]
  access_token.post(url, body, {'Content-Type' => 'application/xml' })
end

#put(url, options = {}, header = {}) ⇒ Object

Execute a signed OAuth PUT request.

Parameters:

  • url (String)

    the url to be requested

  • options (Hash) (defaults to: {})

    optional option attributes

  • header (Hash) (defaults to: {})

    optional header attributes



23
24
25
26
# File 'lib/rosemary/oauth_client.rb', line 23

def put(url, options={}, header={})
  body = options[:body]
  access_token.put(url, body, {'Content-Type' => 'application/xml' })
end