rightsignature-railstyle 1.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/CONTRIBUTING.md +26 -0
- data/Gemfile +2 -0
- data/README.md +443 -0
- data/Rakefile +2 -0
- data/lib/rightsignature.rb +15 -0
- data/lib/rightsignature/account.rb +37 -0
- data/lib/rightsignature/connection.rb +207 -0
- data/lib/rightsignature/connection/oauth_connection.rb +109 -0
- data/lib/rightsignature/connection/token_connection.rb +36 -0
- data/lib/rightsignature/document.rb +333 -0
- data/lib/rightsignature/errors.rb +51 -0
- data/lib/rightsignature/helpers/normalizing.rb +137 -0
- data/lib/rightsignature/helpers/refine_hash_to_indifferent_access.rb +23 -0
- data/lib/rightsignature/rails_style.rb +89 -0
- data/lib/rightsignature/template.rb +299 -0
- data/lib/rightsignature/version.rb +3 -0
- data/rightsignature-api.gemspec +26 -0
- data/spec/account_spec.rb +54 -0
- data/spec/api_token_connection_spec.rb +27 -0
- data/spec/configuration_spec.rb +98 -0
- data/spec/connection_spec.rb +224 -0
- data/spec/document_spec.rb +301 -0
- data/spec/errors_spec.rb +153 -0
- data/spec/normalizing_spec.rb +85 -0
- data/spec/oauth_connnection_spec.rb +143 -0
- data/spec/rails_style_spec.rb +331 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/template_spec.rb +408 -0
- metadata +143 -0
| @@ -0,0 +1,26 @@ | |
| 1 | 
            +
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            +
            $:.push File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            require "rightsignature/version"
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Gem::Specification.new do |s|
         | 
| 6 | 
            +
              s.name        = "rightsignature-railstyle"
         | 
| 7 | 
            +
              s.version     = RightSignature::VERSION
         | 
| 8 | 
            +
              s.platform    = Gem::Platform::RUBY
         | 
| 9 | 
            +
              s.authors     = ["Nick Barone"]
         | 
| 10 | 
            +
              s.email       = [""]
         | 
| 11 | 
            +
              s.homepage    = "http://github.com/narfanator/rightsignature-api"
         | 
| 12 | 
            +
              s.summary     = "API wrapper for RightSignature"
         | 
| 13 | 
            +
              s.description = "Provides a wrapper for the RightSignature API."
         | 
| 14 | 
            +
              s.license     = 'MIT'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              s.add_development_dependency "bundler", ">= 1.0.0"
         | 
| 17 | 
            +
              s.add_development_dependency "rspec", ">= 2.11.0"
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              s.add_dependency "oauth", ">= 0.4.0"
         | 
| 20 | 
            +
              s.add_dependency "httparty", ">= 0.9.0"
         | 
| 21 | 
            +
              s.add_dependency 'xml-fu', '>= 0.2.0'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              s.files        = `git ls-files`.split("\n")
         | 
| 24 | 
            +
              s.executables  = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
         | 
| 25 | 
            +
              s.require_path = 'lib'
         | 
| 26 | 
            +
            end
         | 
| @@ -0,0 +1,54 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/spec_helper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe RightSignature::Account do
         | 
| 4 | 
            +
              describe "user_details" do
         | 
| 5 | 
            +
                it "should GET /api/users/user_details.xml" do
         | 
| 6 | 
            +
                  @rs.should_receive(:get).with('/api/users/user_details.xml')
         | 
| 7 | 
            +
                  @rs.user_details
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
             | 
| 11 | 
            +
              describe "add_user" do
         | 
| 12 | 
            +
                it "should POST /api/users.xml with user email and name in hash" do
         | 
| 13 | 
            +
                  @rs.should_receive(:post).with('/api/users.xml', {:user => {:name => "Jimmy Cricket", :email => "jimmy@example.com"}})
         | 
| 14 | 
            +
                  @rs.add_user("Jimmy Cricket", "jimmy@example.com")
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              describe "usage_report" do
         | 
| 19 | 
            +
                it "should GET /api/account/usage_report.xml" do
         | 
| 20 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {})
         | 
| 21 | 
            +
                  @rs.usage_report
         | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                it "should GET /api/account/usage_report.xml with acceptable param for :since" do
         | 
| 25 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "week"})
         | 
| 26 | 
            +
                  @rs.usage_report("week")
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "month"})
         | 
| 29 | 
            +
                  @rs.usage_report("month")
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:since => "day"})
         | 
| 32 | 
            +
                  @rs.usage_report("day")
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {})
         | 
| 35 | 
            +
                  @rs.usage_report("1/4/90")
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
                
         | 
| 38 | 
            +
                it "should GET /api/account/usage_report.xml with param :signed" do
         | 
| 39 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "true"})
         | 
| 40 | 
            +
                  @rs.usage_report(nil, true)
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "false"})
         | 
| 43 | 
            +
                  @rs.usage_report(nil, false)
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                it "should GET /api/account/usage_report.xml with params :since and :signed" do
         | 
| 47 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "true"})
         | 
| 48 | 
            +
                  @rs.usage_report(nil, true)
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  @rs.should_receive(:get).with('/api/account/usage_report.xml', {:signed => "false"})
         | 
| 51 | 
            +
                  @rs.usage_report(nil, false)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
            end
         | 
| @@ -0,0 +1,27 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/spec_helper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe RightSignature::TokenConnection do
         | 
| 4 | 
            +
              it "should raise error if no configuration is set" do
         | 
| 5 | 
            +
                token_connection = RightSignature::TokenConnection.new('')
         | 
| 6 | 
            +
                lambda{token_connection.request(:get, "path", {:query => {:search => 'hey there'}})}.should raise_error(Exception, "Please set api_token")
         | 
| 7 | 
            +
              end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              it "should create 'api-token' in headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
         | 
| 10 | 
            +
                token_connection = RightSignature::TokenConnection.new('APITOKEN')
         | 
| 11 | 
            +
                token_connection.class.should_receive(:get).with("path", {:query => {:search => 'hey there'}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
         | 
| 12 | 
            +
                token_connection.request(:get, "path", {:query => {:search => 'hey there'}})
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
              
         | 
| 15 | 
            +
              it "should add 'api-token' to headers with :api_token credentials, accept of '*/*', and content-type of xml with given method" do
         | 
| 16 | 
            +
                token_connection = RightSignature::TokenConnection.new('APITOKEN')
         | 
| 17 | 
            +
                token_connection.class.should_receive(:get).with("path", {:query => {:search => 'hey there'}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml", :my_header => "someHeader"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
         | 
| 18 | 
            +
                token_connection.request(:get, "path", {:query => {:search => 'hey there'}, :headers => {:my_header => "someHeader"}})
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              it "should create 'api-token' in headers with :api_token credentials, accept of '*/*', and content-type of xml to POST method" do
         | 
| 22 | 
            +
                token_connection = RightSignature::TokenConnection.new('APITOKEN')
         | 
| 23 | 
            +
                token_connection.class.should_receive(:post).with("path", {:body => {:document => {:roles => []}}, :headers => {"api-token" => "APITOKEN", "Accept" => "*/*", "content-type" => "application/xml"}}).and_return(stub("HTTPartyResponse", :parsed_response => nil))
         | 
| 24 | 
            +
                token_connection.request(:post, "path", {:body => {:document => {:roles => []}}})
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
              
         | 
| 27 | 
            +
            end
         | 
| @@ -0,0 +1,98 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/../lib/rightsignature'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe RightSignature do
         | 
| 4 | 
            +
              describe "load_configuration" do
         | 
| 5 | 
            +
                it "should load api_token into configurations[:api_token]" do
         | 
| 6 | 
            +
                  rs = RightSignature::Connection.new(:api_token => "MyToken")
         | 
| 7 | 
            +
                  rs.configuration[:api_token].should == "MyToken"
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it "should load OAuth consumer key, consumer secret, access token and access secret" do
         | 
| 11 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
         | 
| 12 | 
            +
                  rs.configuration[:consumer_key].should == "key"
         | 
| 13 | 
            +
                  rs.configuration[:consumer_secret].should == "secret"
         | 
| 14 | 
            +
                  rs.configuration[:access_token].should == "atoken"
         | 
| 15 | 
            +
                  rs.configuration[:access_secret].should == "asecret"
         | 
| 16 | 
            +
                end
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              describe "check_credentials" do
         | 
| 20 | 
            +
                it "should raise error if configuration is not set" do
         | 
| 21 | 
            +
                  rs = RightSignature::Connection.new()
         | 
| 22 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                it "should raise error if api_token is blank and oauth credentials are not set" do
         | 
| 26 | 
            +
                  rs = RightSignature::Connection.new(:api_token => " ")
         | 
| 27 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                it "should raise error if consumer_key, consumer_secret, access_token, or access_secret is not set" do
         | 
| 31 | 
            +
                  rs = RightSignature::Connection.new(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
         | 
| 32 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
         | 
| 35 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
         | 
| 38 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
         | 
| 41 | 
            +
                  lambda {rs.check_credentials}.should raise_error
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                it "should not raise error if consumer_key, consumer_secret, access_token, and access_secret is set" do
         | 
| 45 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
         | 
| 46 | 
            +
                  rs.check_credentials
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                it "should not raise error if api_token is set" do
         | 
| 50 | 
            +
                  rs = RightSignature::Connection.new(:api_token => "asdf")
         | 
| 51 | 
            +
                  rs.check_credentials
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
              describe "has_api_token?" do
         | 
| 56 | 
            +
                it "should be false if configuration is not set" do
         | 
| 57 | 
            +
                  rs = RightSignature::Connection.new()
         | 
| 58 | 
            +
                  rs.has_api_token?.should be false
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                it "should be false if api_token is blank" do
         | 
| 62 | 
            +
                  rs = RightSignature::Connection.new(:api_token => "   ")
         | 
| 63 | 
            +
                  rs.has_api_token?.should be false
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                it "should be true if api_token is set" do
         | 
| 67 | 
            +
                  rs = RightSignature::Connection.new(:api_token => "abc")
         | 
| 68 | 
            +
                  rs.has_api_token?.should be true
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              describe "has_oauth_credentials?" do
         | 
| 74 | 
            +
                it "should be false if configuration is not set" do
         | 
| 75 | 
            +
                  rs = RightSignature::Connection.new()
         | 
| 76 | 
            +
                  rs.has_oauth_credentials?.should be false
         | 
| 77 | 
            +
                end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                it "should be false if consumer_key, consumer_secret, access_token, or access_secret is not set" do
         | 
| 80 | 
            +
                  rs = RightSignature::Connection.new(:consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
         | 
| 81 | 
            +
                  rs.has_oauth_credentials?.should be false
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :access_token => "atoken", :access_secret => "asecret")
         | 
| 84 | 
            +
                  rs.has_oauth_credentials?.should be false
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_secret => "asecret")
         | 
| 87 | 
            +
                  rs.has_oauth_credentials?.should be false
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken")
         | 
| 90 | 
            +
                  rs.has_oauth_credentials?.should be false
         | 
| 91 | 
            +
                end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
                it "should be true if consumer_key, consumer_secret, access_token, and access_secret is set" do
         | 
| 94 | 
            +
                  rs = RightSignature::Connection.new(:consumer_key => "key", :consumer_secret => "secret", :access_token => "atoken", :access_secret => "asecret")
         | 
| 95 | 
            +
                  rs.has_oauth_credentials?.should be true
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
            end
         | 
| @@ -0,0 +1,224 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/../lib/rightsignature'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe RightSignature::Connection do
         | 
| 4 | 
            +
              before do
         | 
| 5 | 
            +
                @net_http_response = Net::HTTPOK.new('1.1', 200, 'OK')
         | 
| 6 | 
            +
                @net_http_response.stub(:body => '')
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                @httparty_response = stub("HTTPartyResponse", :body => '')
         | 
| 9 | 
            +
                @httparty_response.stub(:parsed_response) {nil}
         | 
| 10 | 
            +
                @httparty_response.stub(:success?) {true}
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              describe "GET" do
         | 
| 14 | 
            +
                describe "connection method" do
         | 
| 15 | 
            +
                  it "should default to RightSignature::57 if no api_token was specified" do
         | 
| 16 | 
            +
                    @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 17 | 
            +
                    @rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
         | 
| 18 | 
            +
                    @rs.get("/path")
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                  it "should use Token Connection if api_token was specified" do
         | 
| 22 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 23 | 
            +
                    @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 24 | 
            +
                    @rs.get("/path")
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  it "should use Token Connection if only api_token was specified" do
         | 
| 28 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
         | 
| 29 | 
            +
                    @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 30 | 
            +
                    @rs.get("/path")
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                it "should raise error if no configuration is set" do
         | 
| 35 | 
            +
                  @rs = RightSignature::Connection.new({})
         | 
| 36 | 
            +
                  lambda{@rs.get("/path")}.should raise_error
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                describe "using OauthConnection" do
         | 
| 40 | 
            +
                  it "should append params into path alphabetically and URI escaped" do
         | 
| 41 | 
            +
                    @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 42 | 
            +
                    @net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 43 | 
            +
                    @rs.oauth_connection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(@net_http_response)
         | 
| 44 | 
            +
                    @rs.get("/path", {:q => 'search me', :page => 1})
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  it "should return converted response body from XML to hash" do
         | 
| 48 | 
            +
                    @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 49 | 
            +
                    response = Net::HTTPSuccess.new('1.1', 200, 'OK')
         | 
| 50 | 
            +
                    response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 51 | 
            +
                    @rs.oauth_connection.should_receive(:request).with(:get, "/path?page=1&q=search%20me", {}).and_return(response)
         | 
| 52 | 
            +
                    @rs.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                describe "using TokenConnection" do
         | 
| 57 | 
            +
                  it "should append params and header into query option and header option" do
         | 
| 58 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 59 | 
            +
                    @rs.token_connection.should_receive(:request).with(:get, "/path", {:query => {:q => 'search me', :page => 1}, :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
         | 
| 60 | 
            +
                    @rs.get("/path", {:q => 'search me', :page => 1}, {"User-Agent" => "me"})
         | 
| 61 | 
            +
                  end
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  it "should return converted parsed_response from response" do
         | 
| 64 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 65 | 
            +
                    @httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
         | 
| 66 | 
            +
                    @rs.token_connection.stub(:request).and_return(@httparty_response)
         | 
| 67 | 
            +
                    @rs.get("/path", {:q => 'search me', :page => 1}).should == {'document' => {'subject' => "My Subject"}}
         | 
| 68 | 
            +
                  end
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              describe "POST" do
         | 
| 73 | 
            +
                describe "connection method" do
         | 
| 74 | 
            +
                  before do
         | 
| 75 | 
            +
                    @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 76 | 
            +
                    @rs.token_connection.stub(:request => @net_http_response)
         | 
| 77 | 
            +
                    @rs.oauth_connection.stub(:request => @httparty_response)
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  it "should default to Oauth Connection if no api_token was specified" do
         | 
| 81 | 
            +
                    @rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
         | 
| 82 | 
            +
                    @rs.post("/path")
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                  it "should default to Token Connection if api_token was specified" do
         | 
| 86 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 87 | 
            +
                    @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 88 | 
            +
                    @rs.post("/path")
         | 
| 89 | 
            +
                  end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  it "should default to Token Connection if only api_token was specified" do
         | 
| 92 | 
            +
                    @rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
         | 
| 93 | 
            +
                    @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 94 | 
            +
                    @rs.post("/path")
         | 
| 95 | 
            +
                  end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                  it "should raise error if no configuration is set" do
         | 
| 98 | 
            +
                    @rs = RightSignature::Connection.new({})
         | 
| 99 | 
            +
                    lambda{@rs.post("/path")}.should raise_error
         | 
| 100 | 
            +
                  end
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
             | 
| 104 | 
            +
                describe "DELETE" do
         | 
| 105 | 
            +
                  describe "connection method" do
         | 
| 106 | 
            +
                    it "should default to RightSignature::57 if no api_token was specified" do
         | 
| 107 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 108 | 
            +
                      @rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
         | 
| 109 | 
            +
                      @rs.delete("/path")
         | 
| 110 | 
            +
                    end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                    it "should use Token Connection if api_token was specified" do
         | 
| 113 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 114 | 
            +
                      @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 115 | 
            +
                      @rs.delete("/path")
         | 
| 116 | 
            +
                    end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                    it "should use Token Connection if only api_token was specified" do
         | 
| 119 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
         | 
| 120 | 
            +
                      @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 121 | 
            +
                      @rs.delete("/path")
         | 
| 122 | 
            +
                    end
         | 
| 123 | 
            +
                  end
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                  it "should raise error if no configuration is set" do
         | 
| 126 | 
            +
                    @rs = RightSignature::Connection.new({})
         | 
| 127 | 
            +
                    lambda{@rs.delete("/path")}.should raise_error
         | 
| 128 | 
            +
                  end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                  describe "using OauthConnection" do
         | 
| 131 | 
            +
                    it "should return converted response body from XML to hash" do
         | 
| 132 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 133 | 
            +
                      response = Net::HTTPSuccess.new('1.1', 200, 'OK')
         | 
| 134 | 
            +
                      response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 135 | 
            +
                      @rs.oauth_connection.should_receive(:request).with(:delete, "/path", {}).and_return(response)
         | 
| 136 | 
            +
                      @rs.delete("/path").should == {'document' => {'subject' => "My Subject"}}
         | 
| 137 | 
            +
                    end
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                    it "should pass headers" do
         | 
| 140 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 141 | 
            +
                      response = Net::HTTPSuccess.new('1.1', 200, 'OK')
         | 
| 142 | 
            +
                      response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 143 | 
            +
                      @rs.oauth_connection.should_receive(:request).with(:delete, "/path", {"User-Agent" => "custom"}).and_return(response)
         | 
| 144 | 
            +
                      @rs.delete("/path", {"User-Agent" => "custom"}).should == {'document' => {'subject' => "My Subject"}}
         | 
| 145 | 
            +
                    end
         | 
| 146 | 
            +
                  end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                  describe "using TokenConnection" do
         | 
| 149 | 
            +
                    it "should append headers into headers option" do
         | 
| 150 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 151 | 
            +
                      @rs.token_connection.should_receive(:request).with(:delete, "/path", {:headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
         | 
| 152 | 
            +
                      @rs.delete("/path", {"User-Agent" => "me"})
         | 
| 153 | 
            +
                    end
         | 
| 154 | 
            +
             | 
| 155 | 
            +
                    it "should return converted parsed_response from response" do
         | 
| 156 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 157 | 
            +
                      @httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
         | 
| 158 | 
            +
                      @rs.token_connection.stub(:request).and_return(@httparty_response)
         | 
| 159 | 
            +
                      @rs.delete("/path").should == {'document' => {'subject' => "My Subject"}}
         | 
| 160 | 
            +
                    end
         | 
| 161 | 
            +
                  end
         | 
| 162 | 
            +
                end
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                describe "PUT" do
         | 
| 165 | 
            +
                  describe "connection method" do
         | 
| 166 | 
            +
                    it "should default to RightSignature::57 if no api_token was specified" do
         | 
| 167 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 168 | 
            +
                      @rs.oauth_connection.should_receive(:request).and_return(@net_http_response)
         | 
| 169 | 
            +
                      @rs.get("/path")
         | 
| 170 | 
            +
                    end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                    it "should use Token Connection if api_token was specified" do
         | 
| 173 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => "APITOKEN", :consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 174 | 
            +
                      @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 175 | 
            +
                      @rs.put("/path")
         | 
| 176 | 
            +
                    end
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                    it "should use Token Connection if only api_token was specified" do
         | 
| 179 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => "APITOKEN"})
         | 
| 180 | 
            +
                      @rs.token_connection.should_receive(:request).and_return(@httparty_response)
         | 
| 181 | 
            +
                      @rs.put("/path")
         | 
| 182 | 
            +
                    end
         | 
| 183 | 
            +
                  end
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                  it "should raise error if no configuration is set" do
         | 
| 186 | 
            +
                    @rs = RightSignature::Connection.new({})
         | 
| 187 | 
            +
                    lambda{@rs.put("/path")}.should raise_error
         | 
| 188 | 
            +
                  end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
                  describe "using OauthConnection" do
         | 
| 191 | 
            +
                    it "should convert body into XML" do
         | 
| 192 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 193 | 
            +
                      @net_http_response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 194 | 
            +
                      @rs.oauth_connection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(@net_http_response)
         | 
| 195 | 
            +
                      @rs.put("/path", {:document => {:something => "else", :page => 1}})
         | 
| 196 | 
            +
                    end
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                    it "should return converted response body from XML to hash" do
         | 
| 199 | 
            +
                      @rs = RightSignature::Connection.new({:consumer_key => "Consumer123", :consumer_secret => "Secret098", :access_token => "AccessToken098", :access_secret => "AccessSecret123"})
         | 
| 200 | 
            +
                      response = Net::HTTPSuccess.new('1.1', 200, 'OK')
         | 
| 201 | 
            +
                      response.stub(:body).and_return('<document><subject>My Subject</subject></document>')
         | 
| 202 | 
            +
                      @rs.oauth_connection.should_receive(:request).with(:put, "/path", "<document><something>else</something><page>1</page></document>", {}).and_return(response)
         | 
| 203 | 
            +
                      @rs.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
         | 
| 204 | 
            +
                    end
         | 
| 205 | 
            +
                  end
         | 
| 206 | 
            +
             | 
| 207 | 
            +
                  describe "using TokenConnection" do
         | 
| 208 | 
            +
                    it "should append params and header into query option and header option" do
         | 
| 209 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 210 | 
            +
                      @rs.token_connection.should_receive(:request).with(:put, "/path", {:body => "<document><something>else</something><page>1</page></document>", :headers => {"User-Agent" => "me"}}).and_return(@httparty_response)
         | 
| 211 | 
            +
                      @rs.put("/path", {:document => {:something => "else", :page => 1}}, {"User-Agent" => "me"})
         | 
| 212 | 
            +
                    end
         | 
| 213 | 
            +
             | 
| 214 | 
            +
                    it "should return converted parsed_response from response" do
         | 
| 215 | 
            +
                      @rs = RightSignature::Connection.new({:api_token => 'token'})
         | 
| 216 | 
            +
                      @httparty_response.should_receive(:parsed_response).and_return({'document' => {'subject' => "My Subject"}})
         | 
| 217 | 
            +
                      @rs.token_connection.stub(:request).and_return(@httparty_response)
         | 
| 218 | 
            +
                      @rs.put("/path", {:document => {:something => "else", :page => 1}}).should == {'document' => {'subject' => "My Subject"}}
         | 
| 219 | 
            +
                    end
         | 
| 220 | 
            +
                  end
         | 
| 221 | 
            +
                end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
              end
         | 
| 224 | 
            +
            end
         | 
| @@ -0,0 +1,301 @@ | |
| 1 | 
            +
            require File.dirname(__FILE__) + '/spec_helper.rb'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe RightSignature::Document do
         | 
| 4 | 
            +
              describe "documents_list" do
         | 
| 5 | 
            +
                it "should GET /documents.xml" do
         | 
| 6 | 
            +
                  @rs.should_receive(:get).with('/api/documents.xml', {})
         | 
| 7 | 
            +
                  @rs.documents_list
         | 
| 8 | 
            +
                end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                it "should pass search options to /api/templates.xml" do
         | 
| 11 | 
            +
                  @rs.should_receive(:get).with('/api/documents.xml', {:search => "search", :page => 2})
         | 
| 12 | 
            +
                  @rs.documents_list(:search => "search", :page => 2)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                it "should convert array in options :tags into a string" do
         | 
| 16 | 
            +
                  @rs.should_receive(:get).with('/api/documents.xml', {:tags => "hello,what_is:up"})
         | 
| 17 | 
            +
                  @rs.documents_list(:tags => ['hello', {'what_is' => "up"}])
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                it "should convert array of options :state into a string" do
         | 
| 21 | 
            +
                  @rs.should_receive(:get).with('/api/documents.xml', {:state => 'pending,trashed'})
         | 
| 22 | 
            +
                  @rs.documents_list(:state => ['pending', 'trashed'])
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              describe "details" do
         | 
| 27 | 
            +
                it "should GET /api/documentsMYGUID.xml" do
         | 
| 28 | 
            +
                  @rs.should_receive(:get).with('/api/documents/MYGUID.xml')
         | 
| 29 | 
            +
                  @rs.document_details('MYGUID')
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
              end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              describe "details" do
         | 
| 34 | 
            +
                it "should GET /api/documentsMYGUID.xml" do
         | 
| 35 | 
            +
                  @rs.should_receive(:get).with('/api/documents/MYGUID.xml')
         | 
| 36 | 
            +
                  @rs.document_details('MYGUID')
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              describe "documents_batch_details" do
         | 
| 41 | 
            +
                it "should GET /api/documentsMYGUID1,MYGUID2.xml" do
         | 
| 42 | 
            +
                  @rs.should_receive(:get).with('/api/documents/MYGUID1,MYGUID2/batch_details.xml')
         | 
| 43 | 
            +
                  @rs.documents_batch_details(['MYGUID1','MYGUID2'])
         | 
| 44 | 
            +
                end
         | 
| 45 | 
            +
              end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
              describe "send_reminder" do
         | 
| 48 | 
            +
                it "should POST /api/documentsMYGUID/send_reminders.xml" do
         | 
| 49 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/send_reminders.xml', {})
         | 
| 50 | 
            +
                  @rs.send_reminder('MYGUID')
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
              describe "trash" do
         | 
| 55 | 
            +
                it "should POST /api/documents/MYGUID/trash.xml" do
         | 
| 56 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/trash.xml', {})
         | 
| 57 | 
            +
                  @rs.trash_document('MYGUID')
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              describe "extend_document_expiration" do
         | 
| 62 | 
            +
                it "should POST /api/documents/MYGUID/extend_expiration.xml" do
         | 
| 63 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/extend_expiration.xml', {})
         | 
| 64 | 
            +
                  @rs.extend_document_expiration('MYGUID')
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
              describe "update_document_tags" do
         | 
| 69 | 
            +
                it "should POST /api/documents/MYGUID/update_tags.xml" do
         | 
| 70 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {:tags => []})
         | 
| 71 | 
            +
                  @rs.update_document_tags('MYGUID', [])
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                it "should normalize tags array into expected hash format" do
         | 
| 75 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {
         | 
| 76 | 
            +
                    :tags => [{:tag => {:name => 'myNewOne'}}, {:tag => {:name => 'should_replace', :value => 'the_old_new'}}]
         | 
| 77 | 
            +
                  })
         | 
| 78 | 
            +
                  @rs.update_document_tags('MYGUID', ["myNewOne", {"should_replace" => "the_old_new"}])
         | 
| 79 | 
            +
                end
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                it "should allow empty tags array" do
         | 
| 82 | 
            +
                  @rs.should_receive(:post).with('/api/documents/MYGUID/update_tags.xml', {
         | 
| 83 | 
            +
                    :tags => []
         | 
| 84 | 
            +
                  })
         | 
| 85 | 
            +
                  @rs.update_document_tags('MYGUID', [])
         | 
| 86 | 
            +
                end
         | 
| 87 | 
            +
              end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
              describe "send_document" do
         | 
| 90 | 
            +
                it "should POST /api/documents.xml with document hash containing given subject, document data, recipients, and action of 'send'" do
         | 
| 91 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 92 | 
            +
                    :document => {
         | 
| 93 | 
            +
                      :subject => "subby",
         | 
| 94 | 
            +
                      :document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
         | 
| 95 | 
            +
                      :recipients => [],
         | 
| 96 | 
            +
                      :action => "send"
         | 
| 97 | 
            +
                    }
         | 
| 98 | 
            +
                  })
         | 
| 99 | 
            +
                  document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
         | 
| 100 | 
            +
                  @rs.send_document("subby", [], document_data)
         | 
| 101 | 
            +
                end
         | 
| 102 | 
            +
             | 
| 103 | 
            +
                it "should POST /api/documents.xml should convert recipients into normalized format" do
         | 
| 104 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 105 | 
            +
                    :document => {
         | 
| 106 | 
            +
                      :subject => "subby",
         | 
| 107 | 
            +
                      :document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
         | 
| 108 | 
            +
                      :recipients => [
         | 
| 109 | 
            +
                        {:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
         | 
| 110 | 
            +
                        {:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
         | 
| 111 | 
            +
                      ],
         | 
| 112 | 
            +
                      :action => "send"
         | 
| 113 | 
            +
                    }
         | 
| 114 | 
            +
                  })
         | 
| 115 | 
            +
                  document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
         | 
| 116 | 
            +
                  recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  @rs.send_document("subby", recipients, document_data)
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                it "should POST /api/documents.xml with options" do
         | 
| 122 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 123 | 
            +
                    :document => {
         | 
| 124 | 
            +
                      :subject => "subby",
         | 
| 125 | 
            +
                      :document_data => {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"},
         | 
| 126 | 
            +
                      :recipients => [
         | 
| 127 | 
            +
                        {:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
         | 
| 128 | 
            +
                        {:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
         | 
| 129 | 
            +
                      ],
         | 
| 130 | 
            +
                      :action => "send",
         | 
| 131 | 
            +
                      :description => "My descript",
         | 
| 132 | 
            +
                      :callback_url => "http://example.com/call"
         | 
| 133 | 
            +
                    }
         | 
| 134 | 
            +
                  })
         | 
| 135 | 
            +
                  document_data = {:type => 'base64', :filename => "originalfile.pdf", :value => "mOio90cv"}
         | 
| 136 | 
            +
                  recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                  options = {
         | 
| 139 | 
            +
                    :description => "My descript",
         | 
| 140 | 
            +
                    :callback_url => "http://example.com/call"
         | 
| 141 | 
            +
                  }
         | 
| 142 | 
            +
                  @rs.send_document("subby", recipients, document_data, options)
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
              end
         | 
| 145 | 
            +
             | 
| 146 | 
            +
              describe "send_document_from_data" do
         | 
| 147 | 
            +
                it "should POST /api/documents.xml with document hash containing given subject, Base64 encoded version of document data, recipients, and action of 'send'" do
         | 
| 148 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 149 | 
            +
                    :document => {
         | 
| 150 | 
            +
                      :subject => "subby",
         | 
| 151 | 
            +
                      :document_data => {:type => 'base64', :filename => "my fresh upload.pdf", :value => Base64::encode64("THIS IS MY data")},
         | 
| 152 | 
            +
                      :recipients => [],
         | 
| 153 | 
            +
                      :action => "send"
         | 
| 154 | 
            +
                    }
         | 
| 155 | 
            +
                  })
         | 
| 156 | 
            +
                  @rs.send_document_from_data("THIS IS MY data", "my fresh upload.pdf", "subby", [])
         | 
| 157 | 
            +
                end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                it "should POST /api/documents.xml with options" do
         | 
| 160 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 161 | 
            +
                    :document => {
         | 
| 162 | 
            +
                      :subject => "subby",
         | 
| 163 | 
            +
                      :action => "send",
         | 
| 164 | 
            +
                      :document_data => {:type => 'base64', :filename => "uploaded.pdf", :value => Base64::encode64("THIS")},
         | 
| 165 | 
            +
                      :recipients => [
         | 
| 166 | 
            +
                        {:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
         | 
| 167 | 
            +
                        {:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
         | 
| 168 | 
            +
                      ],
         | 
| 169 | 
            +
                      :description => "My descript",
         | 
| 170 | 
            +
                      :callback_url => "http://example.com/call"
         | 
| 171 | 
            +
                    }
         | 
| 172 | 
            +
                  })
         | 
| 173 | 
            +
             | 
| 174 | 
            +
                  recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
         | 
| 175 | 
            +
                  options = {
         | 
| 176 | 
            +
                    :description => "My descript",
         | 
| 177 | 
            +
                    :callback_url => "http://example.com/call"
         | 
| 178 | 
            +
                  }
         | 
| 179 | 
            +
                  @rs.send_document_from_data("THIS", "uploaded.pdf", "subby", recipients, options)
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
              end
         | 
| 182 | 
            +
             | 
| 183 | 
            +
              describe "send_document_from_file" do
         | 
| 184 | 
            +
                it "should open File and base64 encode it" do
         | 
| 185 | 
            +
                  # Probably get a fixture or something here
         | 
| 186 | 
            +
                  file = File.new(File.dirname(__FILE__) + '/spec_helper.rb')
         | 
| 187 | 
            +
                  fake_data = "abc"
         | 
| 188 | 
            +
                  File.should_receive(:read).with(file).and_return(fake_data)
         | 
| 189 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 190 | 
            +
                    :document => {
         | 
| 191 | 
            +
                      :subject => "subby",
         | 
| 192 | 
            +
                      :action => "send",
         | 
| 193 | 
            +
                      :document_data => {:type => 'base64', :filename => "spec_helper.rb", :value => Base64::encode64(fake_data)},
         | 
| 194 | 
            +
                      :recipients => []
         | 
| 195 | 
            +
                    }
         | 
| 196 | 
            +
                  })
         | 
| 197 | 
            +
             | 
| 198 | 
            +
                  @rs.send_document_from_file(file, "subby", [])
         | 
| 199 | 
            +
                end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                it "should open path to file and base64 encode it" do
         | 
| 202 | 
            +
                  file_path = '/tmp/temp.pdf'
         | 
| 203 | 
            +
                  fake_data = "abc"
         | 
| 204 | 
            +
                  File.should_receive(:read).with(file_path).and_return(fake_data)
         | 
| 205 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 206 | 
            +
                    :document => {
         | 
| 207 | 
            +
                      :subject => "subby",
         | 
| 208 | 
            +
                      :action => "send",
         | 
| 209 | 
            +
                      :document_data => {:type => 'base64', :filename => "temp.pdf", :value => Base64::encode64(fake_data)},
         | 
| 210 | 
            +
                      :recipients => []
         | 
| 211 | 
            +
                    }
         | 
| 212 | 
            +
                  })
         | 
| 213 | 
            +
                  @rs.send_document_from_file(file_path, "subby", [])
         | 
| 214 | 
            +
                end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
                it "should POST /api/documents.xml with options" do
         | 
| 217 | 
            +
                  file_path = '/tmp/temp.pdf'
         | 
| 218 | 
            +
                  fake_data = "abc"
         | 
| 219 | 
            +
                  File.should_receive(:read).with(file_path).and_return(fake_data)
         | 
| 220 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 221 | 
            +
                    :document => {
         | 
| 222 | 
            +
                      :subject => "subby",
         | 
| 223 | 
            +
                      :action => "send",
         | 
| 224 | 
            +
                      :document_data => {:type => 'base64', :filename => "temp.pdf", :value => Base64::encode64(fake_data)},
         | 
| 225 | 
            +
                      :recipients => [
         | 
| 226 | 
            +
                        {:recipient => {:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}},
         | 
| 227 | 
            +
                        {:recipient =>{:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}}
         | 
| 228 | 
            +
                      ],
         | 
| 229 | 
            +
                      :description => "My descript",
         | 
| 230 | 
            +
                      :callback_url => "http://example.com/call"
         | 
| 231 | 
            +
                    }
         | 
| 232 | 
            +
                  })
         | 
| 233 | 
            +
             | 
| 234 | 
            +
                  recipients = [{:name => "Signy Sign", :email => "signy@example.com", :role => "signer"}, {:name => "Cee Cee", :email => "ccme@example.com", :role => "cc"}]
         | 
| 235 | 
            +
                  options = {
         | 
| 236 | 
            +
                    :description => "My descript",
         | 
| 237 | 
            +
                    :callback_url => "http://example.com/call"
         | 
| 238 | 
            +
                  }
         | 
| 239 | 
            +
                  @rs.send_document_from_file(file_path, "subby", recipients, options)
         | 
| 240 | 
            +
                end
         | 
| 241 | 
            +
              end
         | 
| 242 | 
            +
             | 
| 243 | 
            +
              describe "generate_document_url" do
         | 
| 244 | 
            +
                it "should POST /api/documents.xml with redirect action and return https://rightsignature.com/builder/new?rt=REDIRECT_TOKEN" do
         | 
| 245 | 
            +
                  @rs.should_receive(:post).with("/api/documents.xml", {
         | 
| 246 | 
            +
                    :document => {
         | 
| 247 | 
            +
                      :subject => "subjy",
         | 
| 248 | 
            +
                      :action => "redirect",
         | 
| 249 | 
            +
                      :document_data => {},
         | 
| 250 | 
            +
                      :recipients => [],
         | 
| 251 | 
            +
                    }
         | 
| 252 | 
            +
                  }).and_return({"document"=>{"redirect_token" => "REDIRECT_TOKEN"}})
         | 
| 253 | 
            +
                  @rs.generate_document_redirect_url("subjy", [], {}).should == "#{@rs.site}/builder/new?rt=REDIRECT_TOKEN"
         | 
| 254 | 
            +
                end
         | 
| 255 | 
            +
              end
         | 
| 256 | 
            +
             | 
| 257 | 
            +
              describe "get_document_signer_links_for" do
         | 
| 258 | 
            +
                it "should GET /api/documents/GUID123/signer_links.xml and return urls for signers" do
         | 
| 259 | 
            +
                  @rs.should_receive(:get).with("/api/documents/GUID123/signer_links.xml", {}).and_return({'document' => {'signer_links' => {'signer_link' => [
         | 
| 260 | 
            +
                    {"signer_token" => "avx37", "name" => "John Bellingham"},
         | 
| 261 | 
            +
                    {"signer_token" => "fdh89", "name" => "Righty Jones"}]
         | 
| 262 | 
            +
                  }}})
         | 
| 263 | 
            +
             | 
| 264 | 
            +
                  response = @rs.get_document_signer_links_for("GUID123")
         | 
| 265 | 
            +
                  response.size.should == 2
         | 
| 266 | 
            +
                  response.include?({"name" => "John Bellingham", "url" => "#{@rs.site}/signatures/embedded?rt=avx37"}).should be true
         | 
| 267 | 
            +
                  response.include?({"name" => "Righty Jones", "url" => "#{@rs.site}/signatures/embedded?rt=fdh89"}).should be true
         | 
| 268 | 
            +
                end
         | 
| 269 | 
            +
             | 
| 270 | 
            +
                it "should GET /api/documents/GUID123/signer_links.xml with URI encoded redirect location and return urls for signers" do
         | 
| 271 | 
            +
                  @rs.should_receive(:get).with("/api/documents/GUID123/signer_links.xml", {:redirect_location => "http://google.com/redirected%20location"}
         | 
| 272 | 
            +
                  ).and_return({'document' => {'signer_links' => {'signer_link' => [
         | 
| 273 | 
            +
                    {"signer_token" => "avx37", "name" => "John Bellingham"},
         | 
| 274 | 
            +
                    {"signer_token" => "fdh89", "name" => "Righty Jones"}]
         | 
| 275 | 
            +
                  }}})
         | 
| 276 | 
            +
             | 
| 277 | 
            +
                  response = @rs.get_document_signer_links_for("GUID123", "http://google.com/redirected location")
         | 
| 278 | 
            +
                  response.size.should == 2
         | 
| 279 | 
            +
                  response.include?({"name" => "John Bellingham", "url" => "#{@rs.site}/signatures/embedded?rt=avx37"}).should be true
         | 
| 280 | 
            +
                  response.include?({"name" => "Righty Jones", "url" => "#{@rs.site}/signatures/embedded?rt=fdh89"}).should be true
         | 
| 281 | 
            +
                end
         | 
| 282 | 
            +
             | 
| 283 | 
            +
                it "should GET /api/documents/GUID123/signer_links.xml and return [] for no signers" do
         | 
| 284 | 
            +
                  @rs.should_receive(:get).with("/api/documents/GUID123/signer_links.xml", {}).and_return({'document' => {'signer_links' => nil}})
         | 
| 285 | 
            +
             | 
| 286 | 
            +
                  response = @rs.get_document_signer_links_for("GUID123")
         | 
| 287 | 
            +
                  response.should == []
         | 
| 288 | 
            +
                end
         | 
| 289 | 
            +
             | 
| 290 | 
            +
                it "should GET /api/documents/GUID123/signer_links.xml with URI encoded redirect location and return urls for 1 signer_link" do
         | 
| 291 | 
            +
                  @rs.should_receive(:get).with("/api/documents/GUID123/signer_links.xml", {:redirect_location => "http://google.com/redirected%20location"}
         | 
| 292 | 
            +
                  ).and_return({'document' => {'signer_links' => {'signer_link' =>
         | 
| 293 | 
            +
                    {"signer_token" => "fdh89", "name" => "Righty Jones"}
         | 
| 294 | 
            +
                  }}})
         | 
| 295 | 
            +
             | 
| 296 | 
            +
                  response = @rs.get_document_signer_links_for("GUID123", "http://google.com/redirected location")
         | 
| 297 | 
            +
                  response.size.should == 1
         | 
| 298 | 
            +
                  response.include?({"name" => "Righty Jones", "url" => "#{@rs.site}/signatures/embedded?rt=fdh89"}).should be true
         | 
| 299 | 
            +
                end
         | 
| 300 | 
            +
              end
         | 
| 301 | 
            +
            end
         |