From ef29d651ae083dd146ba7d83de1f5c7a3029730b Mon Sep 17 00:00:00 2001 From: btorres Date: Tue, 4 Nov 2014 14:35:26 -0800 Subject: [PATCH 1/2] make domain a respect full access urls --- lib/egnyte.rb | 1 - lib/egnyte/item.rb | 2 +- lib/egnyte/link.rb | 2 +- lib/egnyte/permission.rb | 2 +- lib/egnyte/session.rb | 12 +++++++++--- lib/egnyte/user.rb | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/egnyte.rb b/lib/egnyte.rb index 442cf2d..9c9b6d9 100644 --- a/lib/egnyte.rb +++ b/lib/egnyte.rb @@ -20,5 +20,4 @@ require "egnyte/permission" module Egnyte - EGNYTE_DOMAIN = "egnyte.com" end diff --git a/lib/egnyte/item.rb b/lib/egnyte/item.rb index 7b90830..dd80923 100644 --- a/lib/egnyte/item.rb +++ b/lib/egnyte/item.rb @@ -20,7 +20,7 @@ def fs_path(mode='fs') end def self.fs_path(session, mode='fs') - "https://#{session.domain}.#{EGNYTE_DOMAIN}/#{session.api}/v1/#{mode}/" + "https://#{session.domain}/#{session.api}/v1/#{mode}/" end def move_or_copy(destination_path, action) diff --git a/lib/egnyte/link.rb b/lib/egnyte/link.rb index 743251f..fdc097c 100644 --- a/lib/egnyte/link.rb +++ b/lib/egnyte/link.rb @@ -102,7 +102,7 @@ def link_path end def self.link_path(session) - "https://#{session.domain}.#{EGNYTE_DOMAIN}.com/#{session.api}/v1/links" + "https://#{session.domain}/#{session.api}/v1/links" end end diff --git a/lib/egnyte/permission.rb b/lib/egnyte/permission.rb index 9ce23fd..63a570d 100644 --- a/lib/egnyte/permission.rb +++ b/lib/egnyte/permission.rb @@ -85,7 +85,7 @@ def self.original_permissions(session, path, params=nil) end def self.permission_path(session) - "https://#{session.domain}.#{EGNYTE_DOMAIN}/#{session.api}/v1/perms/folder" + "https://#{session.domain}/#{session.api}/v1/perms/folder" end def valid? diff --git a/lib/egnyte/session.rb b/lib/egnyte/session.rb index 27416de..8577be7 100644 --- a/lib/egnyte/session.rb +++ b/lib/egnyte/session.rb @@ -16,10 +16,16 @@ def initialize(opts, strategy=:implicit, backoff=0.5) @api = 'pubapi' # currently we only support the public API. # the domain of the egnyte account to interact with. - raise Egnyte::DomainRequired unless @domain = opts[:domain] + raise Egnyte::DomainRequired unless opts_domain = opts[:domain] + + if opts_domain =~ /.*\..*/ + @domain = opts[:domain] + else + @domain = "#{opts_domain}.egnyte.com" + end @client = OAuth2::Client.new(opts[:key], nil, { - :site => "https://#{@domain}.#{EGNYTE_DOMAIN}", + :site => "https://#{@domain}", :authorize_url => "/puboauth/token", :token_url => "/puboauth/token" }) @@ -39,7 +45,7 @@ def initialize(opts, strategy=:implicit, backoff=0.5) :password => @password, :grant_type => 'password' } - response = RestClient.post "https://#{@domain}.#{EGNYTE_DOMAIN}/puboauth/token", token_request_params + response = RestClient.post "https://#{@domain}/puboauth/token", token_request_params token = JSON.parse(response)["access_token"] @access_token = OAuth2::AccessToken.new(@client, token) else diff --git a/lib/egnyte/user.rb b/lib/egnyte/user.rb index d35badf..e5e5dba 100644 --- a/lib/egnyte/user.rb +++ b/lib/egnyte/user.rb @@ -191,7 +191,7 @@ def user_path end def self.user_path(session) - "https://#{session.domain}.#{EGNYTE_DOMAIN}/#{session.api}/v2/users" + "https://#{session.domain}/#{session.api}/v2/users" end def user_permission_path @@ -199,7 +199,7 @@ def user_permission_path end def self.user_permission_path(session) - "https://#{session.domain}.#{EGNYTE_DOMAIN}/#{session.api}/v1/perms/user" + "https://#{session.domain}/#{session.api}/v1/perms/user" end end From ebc0d1b59b2bd76e43259141f32cf64c54d01df2 Mon Sep 17 00:00:00 2001 From: btorres Date: Tue, 4 Nov 2014 15:01:25 -0800 Subject: [PATCH 2/2] fix specs to use a string of a json hash, not a raw hash object --- spec/folder_spec.rb | 2 +- spec/links_spec.rb | 2 +- spec/user_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/folder_spec.rb b/spec/folder_spec.rb index 8c57138..fc4fdad 100644 --- a/spec/folder_spec.rb +++ b/spec/folder_spec.rb @@ -172,7 +172,7 @@ it "should call the apply method in Egnyte::Permission" do stub_request(:post, "https://test.egnyte.com/pubapi/v1/perms/folder/Shared") .with(:headers => { 'Authorization' => 'Bearer access_token' }) - .to_return(:body => {}, :status => 200) + .to_return(:body => '{}', :status => 200) perm_obj = Egnyte::Permission.build_from_api_listing({'users' => [{'subject' => 'thintz', 'permission' => 'Viewer'}]}) folder = Egnyte::Folder.find(@session, 'Shared') expect(Egnyte::Permission).to receive(:apply) diff --git a/spec/links_spec.rb b/spec/links_spec.rb index d177a71..2f50536 100644 --- a/spec/links_spec.rb +++ b/spec/links_spec.rb @@ -131,7 +131,7 @@ it 'should delete a link by id if the link exists' do stub_request(:delete, "https://test.egnyte.com/pubapi/v1/links/jFmtRccgU0") .with(:headers => {'Authorization'=>'Bearer access_token'}) - .to_return(:status => 200, :body => {}, :headers => {}) + .to_return(:status => 200, :body => '{}', :headers => {}) expect(Egnyte::User).to receive(:delete) Egnyte::User.delete(@session, 'jFmtRccgU0') end diff --git a/spec/user_spec.rb b/spec/user_spec.rb index d5f0002..6c5f946 100644 --- a/spec/user_spec.rb +++ b/spec/user_spec.rb @@ -171,7 +171,7 @@ it 'should delete a user by id if the user exists' do stub_request(:delete, "https://test.egnyte.com/pubapi/v2/users/12408258604") .with(:headers => {'Authorization'=>'Bearer access_token'}) - .to_return(:status => 200, :body => {}, :headers => {}) + .to_return(:status => 200, :body => '{}', :headers => {}) expect(Egnyte::User).to receive(:delete).and_return({}) Egnyte::User.delete(@session, 12408258604) end