Class: Auth::Transis::Client
- Inherits:
-
Object
- Object
- Auth::Transis::Client
- Defined in:
- lib/auth-transis-client.rb,
lib/auth-transis-client/version.rb
Constant Summary collapse
- VERSION =
"0.0.4"
Instance Method Summary collapse
- #add_member_to_organization(organization_id, email_address) ⇒ Object
- #fill_in_access_token!(opts) ⇒ Object
- #get_credentials ⇒ Object
- #get_members_of_organization(organization_id) ⇒ Object
- #get_organizations(user_id = nil) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/auth-transis-client.rb', line 10 def initialize(opts={}) fill_in_access_token!(opts) if opts[:site] && opts[:token] @connection = Faraday.new opts[:site] do |conn| conn.request :oauth2, opts[:token] conn.request :json conn.response :json, :content_type => /\bjson$/ conn.use :instrumentation conn.adapter Faraday.default_adapter end else raise <<-ERROR Either provide :token or provide :site, :username, :password, :client_id, and :client_secret ERROR end end |
Instance Method Details
#add_member_to_organization(organization_id, email_address) ⇒ Object
62 63 64 |
# File 'lib/auth-transis-client.rb', line 62 def add_member_to_organization(organization_id, email_address) @connection.post("/api/v1/organizations/#{organization_id}/members.json", :email=>email_address) end |
#fill_in_access_token!(opts) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/auth-transis-client.rb', line 29 def fill_in_access_token!(opts) return if opts[:token] return unless opts[:site] && opts[:username] && opts[:client_id] && opts[:client_secret] connection = Faraday.new opts[:site] do |conn| conn.request :json conn.response :json, :content_type => /\bjson$/ conn.use :instrumentation conn.adapter Faraday.default_adapter end response = connection.post('/oauth/token', :grant_type => 'password', :client_id => opts[:client_id], :client_secret => opts[:client_secret], :username => opts[:username], :password => opts[:password]) raise 'Failed to get an access token' unless response.success? && response.body['access_token'] opts[:token] = response.body['access_token'] end |
#get_credentials ⇒ Object
48 49 50 |
# File 'lib/auth-transis-client.rb', line 48 def get_credentials @connection.get('/api/v1/me.json').body end |
#get_members_of_organization(organization_id) ⇒ Object
58 59 60 |
# File 'lib/auth-transis-client.rb', line 58 def get_members_of_organization(organization_id) @connection.get("/api/v1/organizations/#{organization_id}/members.json").body end |
#get_organizations(user_id = nil) ⇒ Object
52 53 54 55 56 |
# File 'lib/auth-transis-client.rb', line 52 def get_organizations(user_id=nil) = {} [:user_id]=user_id if user_id @connection.get('/api/v1/organizations.json', ).body end |