yammer-client 0.1.2 → 0.1.3
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.
- data.tar.gz.sig +0 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -4
- data/README.md +11 -10
- data/file.txt +1 -0
- data/lib/yammer.rb +7 -11
- data/lib/yammer/api.rb +2 -1
- data/lib/yammer/api/autocomplete.rb +1 -1
- data/lib/yammer/api/group.rb +5 -5
- data/lib/yammer/api/group_membership.rb +2 -2
- data/lib/yammer/api/message.rb +13 -13
- data/lib/yammer/api/network.rb +1 -1
- data/lib/yammer/api/notification.rb +1 -1
- data/lib/yammer/api/pending_attachment.rb +48 -0
- data/lib/yammer/api/search.rb +1 -1
- data/lib/yammer/api/topic.rb +1 -1
- data/lib/yammer/api/user.rb +17 -17
- data/lib/yammer/api_handler.rb +15 -0
- data/lib/yammer/{response.rb → api_response.rb} +6 -6
- data/lib/yammer/base.rb +19 -11
- data/lib/yammer/client.rb +27 -42
- data/lib/yammer/configurable.rb +14 -8
- data/lib/yammer/group.rb +1 -1
- data/lib/yammer/group_membership.rb +1 -1
- data/lib/yammer/http_adapter.rb +74 -0
- data/lib/yammer/message.rb +1 -1
- data/lib/yammer/thread.rb +1 -1
- data/lib/yammer/user.rb +6 -6
- data/lib/yammer/version.rb +1 -1
- data/spec/api/autocomplete_spec.rb +1 -2
- data/spec/api/group_membership_spec.rb +1 -2
- data/spec/api/group_spec.rb +1 -2
- data/spec/api/message_spec.rb +1 -2
- data/spec/api/network_spec.rb +1 -2
- data/spec/api/notification_spec.rb +3 -4
- data/spec/api/pending_attachment_spec.rb +37 -0
- data/spec/api/search_spec.rb +1 -2
- data/spec/api/thread_spec.rb +1 -2
- data/spec/api/topic_spec.rb +1 -2
- data/spec/api/user_spec.rb +15 -2
- data/spec/{response_spec.rb → api_response.rb} +9 -8
- data/spec/client_spec.rb +203 -66
- data/spec/fixtures/users_followed.json +1 -0
- data/spec/fixtures/users_following.json +1 -0
- data/spec/http_adapter_spec.rb +90 -0
- data/spec/mocks/attachment.txt +1 -0
- data/spec/model/base_spec.rb +26 -5
- data/spec/model/group_membership_spec.rb +11 -0
- data/spec/model/group_spec.rb +10 -0
- data/spec/model/message_spec.rb +10 -0
- data/spec/model/thread_spec.rb +6 -0
- data/spec/model/user_spec.rb +53 -0
- data/spec/spec_helper.rb +8 -0
- data/yammer.gemspec +3 -1
- metadata +35 -10
- metadata.gz.sig +0 -0
- data/lib/yammer/http_connection.rb +0 -184
- data/lib/yammer/model.rb +0 -6
- data/spec/connection_spec.rb +0 -306
    
        data/lib/yammer/message.rb
    CHANGED
    
    
    
        data/lib/yammer/thread.rb
    CHANGED
    
    | @@ -33,7 +33,7 @@ module Yammer | |
| 33 33 |  | 
| 34 34 | 
             
                def messages
         | 
| 35 35 | 
             
                  @messages = {}
         | 
| 36 | 
            -
                  result =  | 
| 36 | 
            +
                  result = api_handler.messages_in_thread(self.id)
         | 
| 37 37 | 
             
                  msgs = result.body[:messages].each do |message|
         | 
| 38 38 | 
             
                    msg = Yammer::Message.new(message)
         | 
| 39 39 | 
             
                    @messages["#{msg.id}"] = msg
         | 
    
        data/lib/yammer/user.rb
    CHANGED
    
    | @@ -3,15 +3,15 @@ module Yammer | |
| 3 3 |  | 
| 4 4 | 
             
                # @!scope class
         | 
| 5 5 | 
             
                def self.create(email)
         | 
| 6 | 
            -
                  result =  | 
| 6 | 
            +
                  result = api_handler.create_user(:email => email)
         | 
| 7 7 | 
             
                  return nil unless result.created?
         | 
| 8 | 
            -
                  id = result.headers[ | 
| 8 | 
            +
                  id = result.headers[:location].split('/').last.to_i
         | 
| 9 9 | 
             
                  new(:id => id)
         | 
| 10 10 | 
             
                end
         | 
| 11 11 |  | 
| 12 12 | 
             
                # @!scope class
         | 
| 13 13 | 
             
                def self.current
         | 
| 14 | 
            -
                  result =  | 
| 14 | 
            +
                  result = api_handler.current_user
         | 
| 15 15 | 
             
                  return nil unless result.success?
         | 
| 16 16 | 
             
                  new(result.body)
         | 
| 17 17 | 
             
                end
         | 
| @@ -32,15 +32,15 @@ module Yammer | |
| 32 32 | 
             
                end
         | 
| 33 33 |  | 
| 34 34 | 
             
                def following
         | 
| 35 | 
            -
                   | 
| 35 | 
            +
                  api_handler.users_followed_by(@id)
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 38 | 
             
                def followers
         | 
| 39 | 
            -
                   | 
| 39 | 
            +
                  api_handler.users_following(@id)
         | 
| 40 40 | 
             
                end
         | 
| 41 41 |  | 
| 42 42 | 
             
                def update!(params)
         | 
| 43 | 
            -
                   | 
| 43 | 
            +
                  api_handler.update_user(@id, params)
         | 
| 44 44 | 
             
                end
         | 
| 45 45 | 
             
              end
         | 
| 46 46 | 
             
            end
         | 
    
        data/lib/yammer/version.rb
    CHANGED
    
    
| @@ -7,8 +7,7 @@ describe Yammer::Api::Autocomplete do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
| @@ -7,8 +7,7 @@ describe Yammer::Api::GroupMembership do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/group_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Group do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/message_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Message do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/network_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Network do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
| @@ -7,15 +7,14 @@ describe Yammer::Api::Notification do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
| 15 14 | 
             
              subject { @client }
         | 
| 16 15 |  | 
| 17 | 
            -
              describe '# | 
| 18 | 
            -
                it  | 
| 16 | 
            +
              describe '#notifications' do
         | 
| 17 | 
            +
                it "should fetch authenticated user's notifications" do
         | 
| 19 18 | 
             
                  subject.should_receive(:get).with('/api/v1/streams/notifications')
         | 
| 20 19 | 
             
                  subject.notifications
         | 
| 21 20 | 
             
                end
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require File.expand_path('../../spec_helper', __FILE__)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe Yammer::Api::PendingAttachment do
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              before :all do
         | 
| 6 | 
            +
                @client = Yammer::Client.new(
         | 
| 7 | 
            +
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 | 
            +
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 | 
            +
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 11 | 
            +
                )
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              subject { @client }
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              describe '#get_pending_attachment' do
         | 
| 17 | 
            +
                it 'should fetch a pending attachment' do
         | 
| 18 | 
            +
                  subject.should_receive(:get).with('/api/v1/pending_attachments/2')
         | 
| 19 | 
            +
                  subject.get_pending_attachment(2)
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              describe '#delete_pending_attachment' do
         | 
| 24 | 
            +
                it 'should delete a pending attachment' do
         | 
| 25 | 
            +
                  subject.should_receive(:delete).with('/api/v1/pending_attachments/1')
         | 
| 26 | 
            +
                  subject.delete_pending_attachment(1)
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              describe '#create_pending_attachment' do
         | 
| 31 | 
            +
                it 'should create a pending attachment' do
         | 
| 32 | 
            +
                  attachment = upload('attachment.txt')
         | 
| 33 | 
            +
                  subject.should_receive(:post).with('/api/v1/pending_attachments', :attachment => attachment)
         | 
| 34 | 
            +
                  subject.create_pending_attachment(attachment)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
    
        data/spec/api/search_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Search do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/thread_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Thread do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/topic_spec.rb
    CHANGED
    
    | @@ -7,8 +7,7 @@ describe Yammer::Api::Topic do | |
| 7 7 | 
             
                  :site_url     => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A' | 
| 11 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 12 11 | 
             
                )
         | 
| 13 12 | 
             
              end
         | 
| 14 13 |  | 
    
        data/spec/api/user_spec.rb
    CHANGED
    
    | @@ -8,8 +8,7 @@ describe Yammer::Api::User do | |
| 8 8 | 
             
                  :site_url     => 'https://yammer.com',
         | 
| 9 9 | 
             
                  :client_id     => "PRbTcg9qjgKsp4jjpm1pw",
         | 
| 10 10 | 
             
                  :client_secret => "Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U",
         | 
| 11 | 
            -
                  :access_token  => "TolNOFka9Uls2DxahNi78A" | 
| 12 | 
            -
                  :connection_client  => Yammer::HttpConnection
         | 
| 11 | 
            +
                  :access_token  => "TolNOFka9Uls2DxahNi78A"
         | 
| 13 12 | 
             
                )
         | 
| 14 13 | 
             
              end
         | 
| 15 14 |  | 
| @@ -73,4 +72,18 @@ describe Yammer::Api::User do | |
| 73 72 | 
             
                  @client.current_user
         | 
| 74 73 | 
             
                end
         | 
| 75 74 | 
             
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              describe "users_following" do
         | 
| 77 | 
            +
                it "makes an http request" do
         | 
| 78 | 
            +
                  @client.should_receive(:get).with('/api/v1/users/following/3')
         | 
| 79 | 
            +
                  @client.users_following(3)
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
             | 
| 83 | 
            +
              describe "users_followed_by" do
         | 
| 84 | 
            +
                it "makes an http request" do
         | 
| 85 | 
            +
                  @client.should_receive(:get).with('/api/v1/users/followed_by/4')
         | 
| 86 | 
            +
                  @client.users_followed_by(4)
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
              end
         | 
| 76 89 | 
             
            end
         | 
| @@ -1,14 +1,15 @@ | |
| 1 1 | 
             
            require File.expand_path('../spec_helper', __FILE__)
         | 
| 2 2 | 
             
            require 'yammer/response'
         | 
| 3 3 |  | 
| 4 | 
            -
            describe Yammer:: | 
| 4 | 
            +
            describe Yammer::ApiResponse do
         | 
| 5 5 |  | 
| 6 6 | 
             
              context 'successful response' do
         | 
| 7 | 
            -
                subject  | 
| 8 | 
            -
                   | 
| 9 | 
            -
                   | 
| 10 | 
            -
                   | 
| 11 | 
            -
             | 
| 7 | 
            +
                subject do
         | 
| 8 | 
            +
                  headers = { 'Location' => 'https://www.yammer.com/api/v1/messages/2' }
         | 
| 9 | 
            +
                  body    = '{ "system_message":false, "direct_message":true, "id":10928508, "privacy":"private", "network_id":1 }'
         | 
| 10 | 
            +
                  code    = '200'
         | 
| 11 | 
            +
                  Yammer::ApiResponse.new(headers, body, code)
         | 
| 12 | 
            +
                end
         | 
| 12 13 |  | 
| 13 14 | 
             
                describe '#raw_body' do
         | 
| 14 15 | 
             
                  it 'returns a string' do
         | 
| @@ -37,7 +38,7 @@ describe Yammer::Response do | |
| 37 38 |  | 
| 38 39 | 
             
              context 'failed response' do
         | 
| 39 40 |  | 
| 40 | 
            -
                subject { Yammer:: | 
| 41 | 
            +
                subject { Yammer::ApiResponse.new(double( :headers => {}, :body   => '', :code   => '500')) }
         | 
| 41 42 |  | 
| 42 43 | 
             
                describe '#raw_body' do
         | 
| 43 44 | 
             
                  it 'returns a string' do
         | 
| @@ -47,7 +48,7 @@ describe Yammer::Response do | |
| 47 48 |  | 
| 48 49 | 
             
                describe '#body' do
         | 
| 49 50 | 
             
                  it 'return a hash' do
         | 
| 50 | 
            -
                    expect(subject. | 
| 51 | 
            +
                    expect(subject.body).to eq('')
         | 
| 51 52 | 
             
                  end
         | 
| 52 53 | 
             
                end
         | 
| 53 54 |  | 
    
        data/spec/client_spec.rb
    CHANGED
    
    | @@ -2,13 +2,25 @@ require File.expand_path('../spec_helper', __FILE__) | |
| 2 2 |  | 
| 3 3 | 
             
            describe Yammer::Client do
         | 
| 4 4 |  | 
| 5 | 
            -
              before : | 
| 5 | 
            +
              before :each do
         | 
| 6 6 | 
             
                @configuration = {
         | 
| 7 7 | 
             
                  :site_url      => 'https://www.yammer.com',
         | 
| 8 8 | 
             
                  :client_id     => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 9 9 | 
             
                  :client_secret => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 10 | 
            -
                  :access_token  => 'TolNOFka9Uls2DxahNi78A'
         | 
| 10 | 
            +
                  :access_token  => 'TolNOFka9Uls2DxahNi78A',
         | 
| 11 | 
            +
                  :connection_options => { :max_redirects => 5, :use_ssl => true },
         | 
| 12 | 
            +
                  :headers       => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem #{Yammer::Version}"}
         | 
| 11 13 | 
             
                }
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                Yammer.configure do |config|
         | 
| 16 | 
            +
                  @configuration.each do |key, val|
         | 
| 17 | 
            +
                    config.send("#{key}=", val)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              after :each do
         | 
| 23 | 
            +
                Yammer.reset!
         | 
| 12 24 | 
             
              end
         | 
| 13 25 |  | 
| 14 26 | 
             
              subject { Yammer::Client.new(@configuration) }
         | 
| @@ -16,9 +28,17 @@ describe Yammer::Client do | |
| 16 28 | 
             
              context "with module configuration" do
         | 
| 17 29 |  | 
| 18 30 | 
             
                before :each do
         | 
| 31 | 
            +
                  @default_conf = {
         | 
| 32 | 
            +
                    :site_url      => nil,
         | 
| 33 | 
            +
                    :client_id     => nil,
         | 
| 34 | 
            +
                    :client_secret => nil,
         | 
| 35 | 
            +
                    :access_token  => nil,
         | 
| 36 | 
            +
                    :headers       => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem #{Yammer::Version}"},
         | 
| 37 | 
            +
                    :connection_options => {}
         | 
| 38 | 
            +
                  }
         | 
| 19 39 | 
             
                  Yammer.configure do |config|
         | 
| 20 40 | 
             
                    Yammer::Configurable.keys.each do |key|
         | 
| 21 | 
            -
                      config.send("#{key}=", key)
         | 
| 41 | 
            +
                      config.send("#{key}=", @default_conf[key])
         | 
| 22 42 | 
             
                    end
         | 
| 23 43 | 
             
                  end
         | 
| 24 44 | 
             
                end
         | 
| @@ -29,8 +49,8 @@ describe Yammer::Client do | |
| 29 49 |  | 
| 30 50 | 
             
                it "inherits the module configuration" do
         | 
| 31 51 | 
             
                  client = Yammer::Client.new
         | 
| 32 | 
            -
                   | 
| 33 | 
            -
                    expect(client.instance_variable_get(:"@#{key}")).to eq  | 
| 52 | 
            +
                  @default_conf.each do |key, value|
         | 
| 53 | 
            +
                    expect(client.instance_variable_get(:"@#{key}")).to eq value
         | 
| 34 54 | 
             
                  end
         | 
| 35 55 | 
             
                end
         | 
| 36 56 |  | 
| @@ -41,7 +61,7 @@ describe Yammer::Client do | |
| 41 61 | 
             
                      :client_id          => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 42 62 | 
             
                      :client_secret      => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 43 63 | 
             
                      :access_token       => 'TolNOFka9Uls2DxahNi78A',
         | 
| 44 | 
            -
                      : | 
| 64 | 
            +
                      :headers            => {"Accept"=>"application/json", "User-Agent"=>"Yammer Ruby Gem 0.1.1"},
         | 
| 45 65 | 
             
                      :connection_options => { :max_redirects => 5, :use_ssl => true }
         | 
| 46 66 | 
             
                    }
         | 
| 47 67 | 
             
                  end
         | 
| @@ -57,6 +77,7 @@ describe Yammer::Client do | |
| 57 77 |  | 
| 58 78 | 
             
                  context "after initialization" do
         | 
| 59 79 | 
             
                    it "overrides the module configuration" do
         | 
| 80 | 
            +
                      Yammer.configure {|c| c.connection_options = {}}
         | 
| 60 81 | 
             
                      client = Yammer::Client.new
         | 
| 61 82 | 
             
                      client.configure do |config|
         | 
| 62 83 | 
             
                        @conf.each do |key, value|
         | 
| @@ -70,52 +91,188 @@ describe Yammer::Client do | |
| 70 91 | 
             
                  end
         | 
| 71 92 | 
             
                end
         | 
| 72 93 | 
             
              end
         | 
| 73 | 
            -
                
         | 
| 74 | 
            -
              describe "connection" do
         | 
| 75 | 
            -
                it "looks like an http connection" do
         | 
| 76 | 
            -
                  conn = subject.instance_eval{ connection }
         | 
| 77 | 
            -
                  expect(conn).to respond_to(:send_request)
         | 
| 78 | 
            -
                end
         | 
| 79 94 |  | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 95 | 
            +
             | 
| 96 | 
            +
             | 
| 97 | 
            +
              describe "#connection_options" do
         | 
| 98 | 
            +
                context "with default connection options" do
         | 
| 99 | 
            +
                  it "returns empty hash" do
         | 
| 100 | 
            +
                    expect(subject.connection_options).to eq ({ :max_redirects => 5, :use_ssl => true })
         | 
| 101 | 
            +
                  end
         | 
| 83 102 | 
             
                end
         | 
| 84 | 
            -
              end
         | 
| 85 103 |  | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 104 | 
            +
                context "with custom connection options" do
         | 
| 105 | 
            +
                  it "returns default options" do
         | 
| 106 | 
            +
                    subject.connection_options = { :max_redirects => 5, :use_ssl => true }
         | 
| 107 | 
            +
                    expect(subject.connection_options).to eq ({:max_redirects => 5, :use_ssl => true})
         | 
| 108 | 
            +
                  end
         | 
| 89 109 | 
             
                end
         | 
| 90 110 | 
             
              end
         | 
| 91 111 |  | 
| 92 | 
            -
              describe " | 
| 93 | 
            -
                 | 
| 94 | 
            -
                   | 
| 112 | 
            +
              describe "#request" do
         | 
| 113 | 
            +
                context "when method is not supported" do
         | 
| 114 | 
            +
                  it "raises an error" do
         | 
| 115 | 
            +
                    expect {subject.send(:request, :patch, '/')}.to raise_error
         | 
| 116 | 
            +
                  end
         | 
| 95 117 | 
             
                end
         | 
| 96 118 |  | 
| 97 | 
            -
                 | 
| 98 | 
            -
                   | 
| 119 | 
            +
                context "when method is get" do
         | 
| 120 | 
            +
                  it "returns an http response" do
         | 
| 121 | 
            +
                    path = '/oauth/authorize'
         | 
| 122 | 
            +
                    params = {:client_id => '001337', :client_secret => 'abcxyz'}
         | 
| 123 | 
            +
                    method = :get
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                    normalized_path = '/oauth/authorize?client_id=001337&client_secret=abcxyz'
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                    stub_request(:get, "https://www.yammer.com/oauth/authorize?client_id=001337&client_secret=abcxyz").with(
         | 
| 128 | 
            +
                      :headers => {
         | 
| 129 | 
            +
                        'Accept'=>'application/json',
         | 
| 130 | 
            +
                        'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 131 | 
            +
                    })
         | 
| 132 | 
            +
                    response = subject.send(:request, method, path, params)
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                    expect(response.code).to eq 200
         | 
| 135 | 
            +
                  end
         | 
| 99 136 | 
             
                end
         | 
| 100 137 |  | 
| 101 | 
            -
                 | 
| 102 | 
            -
                   | 
| 138 | 
            +
                context "when method is delete" do
         | 
| 139 | 
            +
                  it "returns an http response" do
         | 
| 140 | 
            +
                    path = '/users/1'
         | 
| 141 | 
            +
             | 
| 142 | 
            +
                    stub_request(:delete, "https://www.yammer.com/users/1").with(
         | 
| 143 | 
            +
                      :headers => {
         | 
| 144 | 
            +
                        'Accept'=>'application/json',
         | 
| 145 | 
            +
                        'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 146 | 
            +
                      }).to_return(:status => 200, :body => "", :headers => {})
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                    response = subject.send(:request, :delete, path)
         | 
| 149 | 
            +
                    expect(response.code).to eq 200
         | 
| 150 | 
            +
                  end
         | 
| 103 151 | 
             
                end
         | 
| 104 | 
            -
              end
         | 
| 105 152 |  | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
                     | 
| 153 | 
            +
                context "when method is post" do
         | 
| 154 | 
            +
                  it "returns an http response" do
         | 
| 155 | 
            +
                    path = '/users'
         | 
| 156 | 
            +
                    params = {:first_name => 'john', :last_name => 'smith'}
         | 
| 157 | 
            +
                    query  = Addressable::URI.form_encode(params)
         | 
| 158 | 
            +
                    headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.headers)
         | 
| 159 | 
            +
             | 
| 160 | 
            +
                    stub_request(:post, "https://www.yammer.com/users").with(
         | 
| 161 | 
            +
                      :body => {
         | 
| 162 | 
            +
                        "first_name"=>"john",
         | 
| 163 | 
            +
                        "last_name"=>"smith"
         | 
| 164 | 
            +
                        },
         | 
| 165 | 
            +
                      :headers => {
         | 
| 166 | 
            +
                        'Accept'=>'application/json',
         | 
| 167 | 
            +
                        'Content-Type'=>'application/x-www-form-urlencoded',
         | 
| 168 | 
            +
                        'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 169 | 
            +
                    }).to_return(:status => 200, :body => "", :headers => {})
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                    response =subject.send(:request, :post, path, params)
         | 
| 172 | 
            +
                    expect(response.code).to eq 200
         | 
| 110 173 | 
             
                  end
         | 
| 111 174 | 
             
                end
         | 
| 112 175 |  | 
| 113 | 
            -
                context " | 
| 114 | 
            -
                  it "returns  | 
| 115 | 
            -
                     | 
| 116 | 
            -
                     | 
| 176 | 
            +
                context "when method is put" do
         | 
| 177 | 
            +
                  it "returns an http response" do
         | 
| 178 | 
            +
                    path = '/users/1'
         | 
| 179 | 
            +
                    params = {:first_name => 'jane', :last_name => 'doe'}
         | 
| 180 | 
            +
                    query  = Addressable::URI.form_encode(params)
         | 
| 181 | 
            +
                    headers = {'Content-Type' => 'application/x-www-form-urlencoded' }.merge(subject.headers)
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                    stub_request(:put, "https://www.yammer.com/users/1").with(
         | 
| 184 | 
            +
                      :body => {
         | 
| 185 | 
            +
                        "first_name" => "jane",
         | 
| 186 | 
            +
                        "last_name"  => "doe"
         | 
| 187 | 
            +
                      },
         | 
| 188 | 
            +
                      :headers => {
         | 
| 189 | 
            +
                        'Accept'=>'application/json',
         | 
| 190 | 
            +
                        'Content-Type'=>'application/x-www-form-urlencoded',
         | 
| 191 | 
            +
                        'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
         | 
| 192 | 
            +
                        'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 193 | 
            +
                      }).
         | 
| 194 | 
            +
                     to_return(:status => 200, :body => "", :headers => {})
         | 
| 195 | 
            +
             | 
| 196 | 
            +
                    response = subject.send(:request, :put, path, params)
         | 
| 197 | 
            +
                    expect(response.code).to eq 200
         | 
| 117 198 | 
             
                  end
         | 
| 118 199 | 
             
                end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                it "follows redirect" do
         | 
| 202 | 
            +
                  params = {:first_name => 'jane', :last_name => 'doe'}
         | 
| 203 | 
            +
                  stub_request(:post, "https://www.yammer.com/users").with(
         | 
| 204 | 
            +
                    :body => params,
         | 
| 205 | 
            +
                    :headers => {
         | 
| 206 | 
            +
                      'Accept' =>'application/json',
         | 
| 207 | 
            +
                      'Accept-Encoding' => 'gzip, deflate',
         | 
| 208 | 
            +
                      'Content-Type'    => 'application/x-www-form-urlencoded',
         | 
| 209 | 
            +
                      'User-Agent'      => "Yammer Ruby Gem #{Yammer::Version}"
         | 
| 210 | 
            +
                    }
         | 
| 211 | 
            +
                  ).to_return(:status => 303, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})
         | 
| 212 | 
            +
             | 
| 213 | 
            +
                  stub_request(:get, "https://www.yammer.com/members").
         | 
| 214 | 
            +
                     with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"}).
         | 
| 215 | 
            +
                     to_return(:status => 200, :body => "", :headers => {})
         | 
| 216 | 
            +
                  response = subject.send(:request, :post, '/users', params)
         | 
| 217 | 
            +
             | 
| 218 | 
            +
                  expect(response.code).to eq 200
         | 
| 219 | 
            +
                end
         | 
| 220 | 
            +
             | 
| 221 | 
            +
                it "respects the redirect limit " do
         | 
| 222 | 
            +
                  subject.connection_options = { :max_redirects => 1 }
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                  stub_request(:get, "https://www.yammer.com/users").
         | 
| 225 | 
            +
                     with(
         | 
| 226 | 
            +
                      :headers => {
         | 
| 227 | 
            +
                        'Accept' => 'application/json',
         | 
| 228 | 
            +
                        'Accept-Encoding'=> 'gzip, deflate',
         | 
| 229 | 
            +
                        'User-Agent'     => "Yammer Ruby Gem #{Yammer::Version}"
         | 
| 230 | 
            +
                      }
         | 
| 231 | 
            +
                    ).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})
         | 
| 232 | 
            +
             | 
| 233 | 
            +
             
         | 
| 234 | 
            +
                   stub_request(:get, "https://www.yammer.com/members").
         | 
| 235 | 
            +
                     with(
         | 
| 236 | 
            +
                      :headers => {
         | 
| 237 | 
            +
                        'Accept' => 'application/json',
         | 
| 238 | 
            +
                        'Accept-Encoding'=> 'gzip, deflate',
         | 
| 239 | 
            +
                        'User-Agent'     => "Yammer Ruby Gem #{Yammer::Version}"
         | 
| 240 | 
            +
                      }
         | 
| 241 | 
            +
                    ).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/people'})
         | 
| 242 | 
            +
             | 
| 243 | 
            +
                  expect { subject.send(:request, :get, '/users') }.to raise_error(RestClient::MaxRedirectsReached)
         | 
| 244 | 
            +
                end
         | 
| 245 | 
            +
             | 
| 246 | 
            +
                it "modifies http 303 redirect from POST to GET " do
         | 
| 247 | 
            +
                  params = { :first_name => 'jane', :last_name => 'doe' }
         | 
| 248 | 
            +
                  stub_request(:post, "https://www.yammer.com/users").with(
         | 
| 249 | 
            +
                    :body => params,
         | 
| 250 | 
            +
                    :headers => {
         | 
| 251 | 
            +
                      'Accept'=>'application/json',
         | 
| 252 | 
            +
                      'Accept-Encoding'=>'gzip, deflate',
         | 
| 253 | 
            +
                      'Content-Length'=>'29',
         | 
| 254 | 
            +
                      'Content-Type'=>'application/x-www-form-urlencoded',
         | 
| 255 | 
            +
                      'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 256 | 
            +
                    }
         | 
| 257 | 
            +
                  ).to_return(
         | 
| 258 | 
            +
                    :status => 303,
         | 
| 259 | 
            +
                    :body => "you are being redirected",
         | 
| 260 | 
            +
                    :headers => {'Location' => "http://yammer.com/members"}
         | 
| 261 | 
            +
                  )
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                  stub_request(:get, "http://yammer.com/members").
         | 
| 264 | 
            +
                    with(
         | 
| 265 | 
            +
                      :headers => {
         | 
| 266 | 
            +
                        'Accept'=>'application/json',
         | 
| 267 | 
            +
                        'Accept-Encoding'=>'gzip, deflate',
         | 
| 268 | 
            +
                        'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
         | 
| 269 | 
            +
                      }
         | 
| 270 | 
            +
                  ).to_return(:status => 200, :body => "", :headers => {})
         | 
| 271 | 
            +
             | 
| 272 | 
            +
                  response = subject.send(:request, :post, '/users', params )
         | 
| 273 | 
            +
             | 
| 274 | 
            +
                  expect(response.code).to eq 200
         | 
| 275 | 
            +
                end
         | 
| 119 276 | 
             
              end
         | 
| 120 277 |  | 
| 121 278 | 
             
              context 'http request' do
         | 
| @@ -127,8 +284,10 @@ describe Yammer::Client do | |
| 127 284 | 
             
                        'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
         | 
| 128 285 | 
             
                        'Content-Type'=>'application/x-www-form-urlencoded',
         | 
| 129 286 | 
             
                        'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
         | 
| 130 | 
            -
                      }, | 
| 131 | 
            -
                      :body => { :name => 'alice' })
         | 
| 287 | 
            +
                      },
         | 
| 288 | 
            +
                      :body => { :name => 'alice' }).to_return({
         | 
| 289 | 
            +
                        :status => 200, :body => "", :headers => {}
         | 
| 290 | 
            +
                      })
         | 
| 132 291 | 
             
                    subject.post('/users', { :name => 'alice'})
         | 
| 133 292 | 
             
                  end
         | 
| 134 293 | 
             
                end
         | 
| @@ -142,7 +301,9 @@ describe Yammer::Client do | |
| 142 301 | 
             
                        'Content-Type'=>'application/x-www-form-urlencoded',
         | 
| 143 302 | 
             
                        'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
         | 
| 144 303 | 
             
                      },
         | 
| 145 | 
            -
                      :body => { :name => 'bob' })
         | 
| 304 | 
            +
                      :body => { :name => 'bob' }).to_return(
         | 
| 305 | 
            +
                        :status => 200, :body => "", :headers => {})
         | 
| 306 | 
            +
             | 
| 146 307 | 
             
                    subject.put('/users/1', { :name => 'bob'})
         | 
| 147 308 | 
             
                  end
         | 
| 148 309 | 
             
                end
         | 
| @@ -165,9 +326,9 @@ describe Yammer::Client do | |
| 165 326 | 
             
                  it 'raises exception' do
         | 
| 166 327 | 
             
                    stub_get('/users/1').with(:headers => { 'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A' }).to_return(
         | 
| 167 328 | 
             
                      :body => '{ "response": { "message": "Token not found.", "code": 16, "stat": "fail" } }',
         | 
| 168 | 
            -
                      :status => 401
         | 
| 169 | 
            -
             | 
| 170 | 
            -
                    expect { subject.get('/users/1') }.to raise_error( | 
| 329 | 
            +
                      :status => 401)
         | 
| 330 | 
            +
             | 
| 331 | 
            +
                    expect { subject.get('/users/1') }.to raise_error(RestClient::Unauthorized)
         | 
| 171 332 | 
             
                  end
         | 
| 172 333 | 
             
                end
         | 
| 173 334 |  | 
| @@ -177,31 +338,7 @@ describe Yammer::Client do | |
| 177 338 | 
             
                      :body => '{ "response": { "message": "Rate limited due to excessive requests.", "code": 33, "stat": "fail" } }',
         | 
| 178 339 | 
             
                      :status => 429
         | 
| 179 340 | 
             
                    )
         | 
| 180 | 
            -
                    expect { subject.get('/users/1') }.to raise_error( | 
| 181 | 
            -
                  end
         | 
| 182 | 
            -
                end
         | 
| 183 | 
            -
              end
         | 
| 184 | 
            -
             | 
| 185 | 
            -
              describe "#connection" do
         | 
| 186 | 
            -
                context "with default connection options" do
         | 
| 187 | 
            -
                  it "returns HttpConnection" do
         | 
| 188 | 
            -
                    expect(subject.send(:connection)).to be_instance_of(Yammer::HttpConnection)
         | 
| 189 | 
            -
                  end
         | 
| 190 | 
            -
                end
         | 
| 191 | 
            -
             | 
| 192 | 
            -
                context "with custom connection options" do
         | 
| 193 | 
            -
                  it "returns custom connection" do
         | 
| 194 | 
            -
                    custom_http  = Struct.new('CustomHttpClient', :site_url, :connection_options)
         | 
| 195 | 
            -
                    client = Yammer::Client.new(
         | 
| 196 | 
            -
                      :site_url           => 'www.example.com',
         | 
| 197 | 
            -
                      :client_id          => 'PRbTcg9qjgKsp4jjpm1pw',
         | 
| 198 | 
            -
                      :client_secret      => 'Xn7kp7Ly0TCY4GtZWkmSsqGEPg10DmMADyjWkf2U',
         | 
| 199 | 
            -
                      :http_adapter       => custom_http,
         | 
| 200 | 
            -
                      :connection_options => { :max_redirects => 5, :use_ssl => true }
         | 
| 201 | 
            -
                    )
         | 
| 202 | 
            -
                    connection = client.send(:connection)
         | 
| 203 | 
            -
                    expect(connection.site_url).to eq "www.example.com"
         | 
| 204 | 
            -
                    expect(connection.connection_options).to eq({ :max_redirects => 5, :use_ssl => true })
         | 
| 341 | 
            +
                    expect { subject.get('/users/1') }.to raise_error(RestClient::RequestFailed)
         | 
| 205 342 | 
             
                  end
         | 
| 206 343 | 
             
                end
         | 
| 207 344 | 
             
              end
         |