lib/centro/client.rb in centro-client-0.0.1 vs lib/centro/client.rb in centro-client-0.0.2
- old
+ new
@@ -27,11 +27,11 @@
def mms_url
url_from_host(mms_host)
end
def url_from_host(host)
(ssl_enabled? ? 'https://' : 'http://') +
- host
+ host + "/api/#{self.api_version}"
end
end
attr_accessor :client_id, :client_secret, :access_token
@@ -50,27 +50,26 @@
:grant_type => 'password',
:client_id => @client_id,
:client_secret => @client_secret,
:username => username,
:password => password)
- raise 'Failed to get an access token' unless response.success? && response.body['access_token']
- self.access_token = response.body['access_token']
+ self.access_token = response.body.access_token
end
def get_credentials
- auth_connection.get("/api/#{self.class.api_version}/me.json").body
+ auth_connection.get("me.json").body
end
def get_organizations(user_id=nil)
options = {}
options[:user_id]=user_id if user_id
- auth_connection.get("/api/#{self.class.api_version}/organizations.json", options).body
+ auth_connection.get("organizations.json", options).body
end
def get_members_of_organization(organization_id)
- auth_connection.get("/api/#{self.class.api_version}/organizations/#{organization_id}/members.json").body
+ auth_connection.get("organizations/#{organization_id}/members.json").body
end
##
# Creates a user in an organization. If the user already exists in AuthTransis they will
# simply be added to the org (assuming the resource owner has rights), if they don't exist
@@ -79,23 +78,23 @@
# Returns a list of the organizations that they were sucessfully added to.
def create_user_in_organization(email, organization_id)
org_ids = organization_id.respond_to?(:each) ? organization_id : [organization_id]
successfuls = []
org_ids.each do |org_id|
- response = auth_connection.post("/api/#{self.class.api_version}/organizations/#{organization_id}/members.json", {:email_address => email})
+ response = auth_connection.post("organizations/#{organization_id}/members.json", {:email_address => email})
response.success? && successfuls << response.body
end
successfuls
end
def create_user(email)
- response = auth_connection.post("/api/#{self.class.api_version}/members.json", {:email_address => email})
+ response = auth_connection.post("members.json", {:email_address => email})
response.success? && response.body
end
def create_organization(org_name)
- response = auth_connection.post("/api/#{self.class.api_version}/organizations", {:name => org_name})
+ response = auth_connection.post("organizations", {:name => org_name})
response.success? && response.body
end
private
@@ -103,9 +102,10 @@
conn.request :json
conn.response :dates
conn.response :mashify
conn.response :json, :content_type => /\bjson$/
+ conn.response :xml, :content_type => /\bxml$/
conn.response :raise_error
conn.adapter Faraday.default_adapter
end