sendgrid4r 0.2.0 → 0.3.0
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 +4 -4
 - data/.env.example +5 -0
 - data/.rubocop.yml +8 -8
 - data/README.md +2 -0
 - data/lib/auth.rb +5 -2
 - data/lib/client.rb +4 -2
 - data/lib/sendgrid4r/factory/version_factory.rb +1 -1
 - data/lib/sendgrid4r/rest/api.rb +4 -0
 - data/lib/sendgrid4r/rest/api_keys/api_keys.rb +73 -0
 - data/lib/sendgrid4r/rest/asm/asm.rb +28 -0
 - data/lib/sendgrid4r/rest/asm/global_suppressions.rb +12 -8
 - data/lib/sendgrid4r/rest/asm/groups.rb +29 -22
 - data/lib/sendgrid4r/rest/asm/suppressions.rb +25 -15
 - data/lib/sendgrid4r/rest/categories/categories.rb +19 -9
 - data/lib/sendgrid4r/rest/contacts/custom_fields.rb +14 -8
 - data/lib/sendgrid4r/rest/contacts/lists.rb +32 -20
 - data/lib/sendgrid4r/rest/contacts/recipients.rb +42 -31
 - data/lib/sendgrid4r/rest/contacts/reserved_fields.rb +6 -2
 - data/lib/sendgrid4r/rest/contacts/segments.rb +22 -12
 - data/lib/sendgrid4r/rest/ips/addresses.rb +36 -22
 - data/lib/sendgrid4r/rest/ips/pools.rb +31 -16
 - data/lib/sendgrid4r/rest/ips/warmup.rb +34 -15
 - data/lib/sendgrid4r/rest/request.rb +33 -19
 - data/lib/sendgrid4r/rest/settings/enforced_tls.rb +12 -5
 - data/lib/sendgrid4r/rest/stats/advanced.rb +73 -25
 - data/lib/sendgrid4r/rest/stats/category.rb +11 -6
 - data/lib/sendgrid4r/rest/stats/global.rb +6 -4
 - data/lib/sendgrid4r/rest/stats/parse.rb +10 -4
 - data/lib/sendgrid4r/rest/stats/stats.rb +13 -18
 - data/lib/sendgrid4r/rest/stats/subuser.rb +10 -6
 - data/lib/sendgrid4r/rest/templates/templates.rb +23 -16
 - data/lib/sendgrid4r/rest/templates/versions.rb +39 -36
 - data/lib/sendgrid4r/version.rb +1 -1
 - data/spec/api_keys/api_keys_spec.rb +152 -0
 - data/spec/asm/asm_spec.rb +33 -0
 - data/spec/asm/global_suppressions_spec.rb +111 -45
 - data/spec/asm/groups_spec.rb +172 -48
 - data/spec/asm/suppressions_spec.rb +180 -54
 - data/spec/categories/categories_spec.rb +81 -25
 - data/spec/client_spec.rb +11 -4
 - data/spec/contacts/custom_fields_spec.rb +135 -44
 - data/spec/contacts/lists_spec.rb +314 -84
 - data/spec/contacts/recipients_spec.rb +337 -92
 - data/spec/contacts/reserved_fields_spec.rb +80 -60
 - data/spec/contacts/segments_spec.rb +219 -88
 - data/spec/factory/condition_factory_spec.rb +12 -12
 - data/spec/factory/segment_factory_spec.rb +19 -19
 - data/spec/factory/version_factory_spec.rb +6 -6
 - data/spec/ips/addresses_spec.rb +177 -84
 - data/spec/ips/pools_spec.rb +190 -34
 - data/spec/ips/warmup_spec.rb +106 -38
 - data/spec/settings/enforced_tls_spec.rb +76 -18
 - data/spec/stats/advanced_spec.rb +373 -196
 - data/spec/stats/category_spec.rb +133 -71
 - data/spec/stats/global_spec.rb +74 -47
 - data/spec/stats/parse_spec.rb +46 -29
 - data/spec/stats/stats_spec.rb +246 -0
 - data/spec/stats/subuser_spec.rb +99 -54
 - data/spec/templates/templates_spec.rb +219 -54
 - data/spec/templates/versions_spec.rb +171 -67
 - metadata +10 -2
 
| 
         @@ -1,94 +1,226 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe  
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
                @client = SendGrid4r::Client.new(
         
     | 
| 
       8 
     | 
    
         
            -
                  ENV['SENDGRID_USERNAME'], ENV['SENDGRID_PASSWORD'])
         
     | 
| 
       9 
     | 
    
         
            -
                @name = 'test_segment'
         
     | 
| 
       10 
     | 
    
         
            -
                @edit_name = 'test_segment_edit'
         
     | 
| 
       11 
     | 
    
         
            -
                @field = 'last_name'
         
     | 
| 
       12 
     | 
    
         
            -
                @value = 'Miller'
         
     | 
| 
       13 
     | 
    
         
            -
                @operator = 'eq'
         
     | 
| 
       14 
     | 
    
         
            -
                @and_or = ''
         
     | 
| 
       15 
     | 
    
         
            -
                @condition_factory = SendGrid4r::Factory::ConditionFactory.new
         
     | 
| 
       16 
     | 
    
         
            -
                @segment_factory = SendGrid4r::Factory::SegmentFactory.new
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              context 'always' do
         
     | 
| 
       20 
     | 
    
         
            -
                it 'is normal' do
         
     | 
| 
      
 4 
     | 
    
         
            +
            describe SendGrid4r::REST::Contacts::Segments do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'integration test' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                before do
         
     | 
| 
       21 
7 
     | 
    
         
             
                  begin
         
     | 
| 
       22 
     | 
    
         
            -
                     
     | 
| 
       23 
     | 
    
         
            -
                     
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
                    Dotenv.load
         
     | 
| 
      
 9 
     | 
    
         
            +
                    @client = SendGrid4r::Client.new(
         
     | 
| 
      
 10 
     | 
    
         
            +
                      username: ENV['SENDGRID_USERNAME'],
         
     | 
| 
      
 11 
     | 
    
         
            +
                      password: ENV['SENDGRID_PASSWORD'])
         
     | 
| 
      
 12 
     | 
    
         
            +
                    @name1 = 'test_segment1'
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @name2 = 'test_segment2'
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @edit_name1 = 'test_segment_edit'
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @field = 'last_name1'
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @value = 'Miller'
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @operator = 'eq'
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @and_or = ''
         
     | 
| 
      
 19 
     | 
    
         
            +
                    @condition_factory = SendGrid4r::Factory::ConditionFactory.new
         
     | 
| 
      
 20 
     | 
    
         
            +
                    @segment_factory = SendGrid4r::Factory::SegmentFactory.new
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                    # celan up test env(segment)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @client.get_segments.segments.each do |segment|
         
     | 
| 
      
 24 
     | 
    
         
            +
                      @client.delete_segment(segment.id) if segment.name == @name1
         
     | 
| 
      
 25 
     | 
    
         
            +
                      @client.delete_segment(segment.id) if segment.name == @edit_name1
         
     | 
| 
      
 26 
     | 
    
         
            +
                      @client.delete_segment(segment.id) if segment.name == @name2
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
      
 28 
     | 
    
         
            +
                    # clean up test env(custom_fields)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @client.get_custom_fields.custom_fields.each do |field|
         
     | 
| 
      
 30 
     | 
    
         
            +
                      @client.delete_custom_field(field.id) if field.name == @field
         
     | 
| 
       28 
31 
     | 
    
         
             
                    end
         
     | 
| 
       29 
     | 
    
         
            -
                    # post a segment
         
     | 
| 
       30 
     | 
    
         
            -
                     
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                      value: @value,
         
     | 
| 
       33 
     | 
    
         
            -
                      operator: @operator,
         
     | 
| 
       34 
     | 
    
         
            -
                      and_or: @and_or
         
     | 
| 
      
 32 
     | 
    
         
            +
                    # post a custom field and a segment
         
     | 
| 
      
 33 
     | 
    
         
            +
                    @client.post_custom_field(@field, 'text')
         
     | 
| 
      
 34 
     | 
    
         
            +
                    @condition = @condition_factory.create(
         
     | 
| 
      
 35 
     | 
    
         
            +
                      field: @field, value: @value, operator: @operator, and_or: @and_or
         
     | 
| 
       35 
36 
     | 
    
         
             
                    )
         
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
       37 
     | 
    
         
            -
                      name: @ 
     | 
| 
      
 37 
     | 
    
         
            +
                    params1 = @segment_factory.create(
         
     | 
| 
      
 38 
     | 
    
         
            +
                      name: @name1, conditions: [@condition]
         
     | 
| 
       38 
39 
     | 
    
         
             
                    )
         
     | 
| 
       39 
     | 
    
         
            -
                     
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                     
     | 
| 
       42 
     | 
    
         
            -
                     
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
                     
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
             
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                       
     | 
| 
       66 
     | 
    
         
            -
                       
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
                    @segment1 = @client.post_segment(params1)
         
     | 
| 
      
 41 
     | 
    
         
            +
                  rescue => e
         
     | 
| 
      
 42 
     | 
    
         
            +
                    puts e.inspect
         
     | 
| 
      
 43 
     | 
    
         
            +
                    raise e
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
                context 'without block call' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  it '#post_segment' do
         
     | 
| 
      
 49 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 50 
     | 
    
         
            +
                      params2 = @segment_factory.create(
         
     | 
| 
      
 51 
     | 
    
         
            +
                        name: @name2, conditions: [@condition]
         
     | 
| 
      
 52 
     | 
    
         
            +
                      )
         
     | 
| 
      
 53 
     | 
    
         
            +
                      segment = @client.post_segment(params2)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      expect(segment.id).to be_a(Fixnum)
         
     | 
| 
      
 55 
     | 
    
         
            +
                      expect(segment.name).to eq(@name2)
         
     | 
| 
      
 56 
     | 
    
         
            +
                      expect(segment.list_id).to eq(nil)
         
     | 
| 
      
 57 
     | 
    
         
            +
                      expect(segment.conditions.length).to eq(1)
         
     | 
| 
      
 58 
     | 
    
         
            +
                      expect(segment.recipient_count).to eq(0)
         
     | 
| 
      
 59 
     | 
    
         
            +
                      condition = segment.conditions[0]
         
     | 
| 
      
 60 
     | 
    
         
            +
                      expect(condition.field).to eq(@field)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      expect(condition.value).to eq(@value)
         
     | 
| 
      
 62 
     | 
    
         
            +
                      expect(condition.operator).to eq(@operator)
         
     | 
| 
      
 63 
     | 
    
         
            +
                      expect(condition.and_or).to eq(nil)
         
     | 
| 
      
 64 
     | 
    
         
            +
                      expect(segment.recipient_count).to eq(0)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 66 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 67 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 68 
     | 
    
         
            +
                    end
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  it '#get_segments' do
         
     | 
| 
      
 72 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 73 
     | 
    
         
            +
                      segments = @client.get_segments
         
     | 
| 
      
 74 
     | 
    
         
            +
                      segments.segments.each do |segment|
         
     | 
| 
      
 75 
     | 
    
         
            +
                        expect(
         
     | 
| 
      
 76 
     | 
    
         
            +
                          segment
         
     | 
| 
      
 77 
     | 
    
         
            +
                        ).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
      
 78 
     | 
    
         
            +
                      end
         
     | 
| 
      
 79 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 80 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 81 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  it '#get_segment' do
         
     | 
| 
      
 86 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 87 
     | 
    
         
            +
                      segment = @client.get_segment(@segment1.id)
         
     | 
| 
      
 88 
     | 
    
         
            +
                      expect(segment.id).to eq(@segment1.id)
         
     | 
| 
      
 89 
     | 
    
         
            +
                      expect(segment.name).to eq(@segment1.name)
         
     | 
| 
      
 90 
     | 
    
         
            +
                      expect(segment.list_id).to eq(nil)
         
     | 
| 
      
 91 
     | 
    
         
            +
                      condition = segment.conditions[0]
         
     | 
| 
      
 92 
     | 
    
         
            +
                      expect(condition.field).to eq(@field)
         
     | 
| 
      
 93 
     | 
    
         
            +
                      expect(condition.value).to eq(@value)
         
     | 
| 
      
 94 
     | 
    
         
            +
                      expect(condition.operator).to eq(@operator)
         
     | 
| 
      
 95 
     | 
    
         
            +
                      expect(condition.and_or).to eq(nil)
         
     | 
| 
      
 96 
     | 
    
         
            +
                      expect(segment.recipient_count).to be_a(Fixnum)
         
     | 
| 
      
 97 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 98 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 99 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 100 
     | 
    
         
            +
                    end
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  it '#put_segment' do
         
     | 
| 
      
 104 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 105 
     | 
    
         
            +
                      pending 'waiting sendgrid documentation update'
         
     | 
| 
      
 106 
     | 
    
         
            +
                      edit_params = @segment_factory.create(
         
     | 
| 
      
 107 
     | 
    
         
            +
                        name: @edit_name1, conditions: [@condition]
         
     | 
| 
      
 108 
     | 
    
         
            +
                      )
         
     | 
| 
      
 109 
     | 
    
         
            +
                      edit_segment = @client.put_segment(@segment1.id, edit_params)
         
     | 
| 
      
 110 
     | 
    
         
            +
                      expect(edit_segment.name).to eq(@edit_name1)
         
     | 
| 
      
 111 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 112 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 113 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 114 
     | 
    
         
            +
                    end
         
     | 
| 
      
 115 
     | 
    
         
            +
                  end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                  it '#get_recipients_from_segment' do
         
     | 
| 
      
 118 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 119 
     | 
    
         
            +
                      # list recipients from a single segment
         
     | 
| 
      
 120 
     | 
    
         
            +
                      recipients = @client.get_recipients_from_segment(@segment1.id)
         
     | 
| 
      
 121 
     | 
    
         
            +
                      recipients.recipients.each do |recipient|
         
     | 
| 
      
 122 
     | 
    
         
            +
                        expect(
         
     | 
| 
      
 123 
     | 
    
         
            +
                          recipient
         
     | 
| 
      
 124 
     | 
    
         
            +
                        ).to be_a(SendGrid4r::REST::Contacts::Recipients::Recipient)
         
     | 
| 
      
 125 
     | 
    
         
            +
                      end
         
     | 
| 
      
 126 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 127 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 128 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 129 
     | 
    
         
            +
                    end
         
     | 
| 
      
 130 
     | 
    
         
            +
                  end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
                  it '#delete_segment' do
         
     | 
| 
      
 133 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 134 
     | 
    
         
            +
                      # delete the segment
         
     | 
| 
      
 135 
     | 
    
         
            +
                      @client.delete_segment(@segment1.id)
         
     | 
| 
      
 136 
     | 
    
         
            +
                    rescue => e
         
     | 
| 
      
 137 
     | 
    
         
            +
                      puts e.inspect
         
     | 
| 
      
 138 
     | 
    
         
            +
                      raise e
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
                  end
         
     | 
| 
      
 141 
     | 
    
         
            +
                end
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                context 'with block all' do
         
     | 
| 
      
 144 
     | 
    
         
            +
                  it '#post_segment' do
         
     | 
| 
      
 145 
     | 
    
         
            +
                    params2 = @segment_factory.create(
         
     | 
| 
      
 146 
     | 
    
         
            +
                      name: @name2, conditions: [@condition]
         
     | 
| 
       68 
147 
     | 
    
         
             
                    )
         
     | 
| 
      
 148 
     | 
    
         
            +
                    @client.post_segment(params2) do |resp, req, res|
         
     | 
| 
      
 149 
     | 
    
         
            +
                      resp =
         
     | 
| 
      
 150 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Segments.create_segment(
         
     | 
| 
      
 151 
     | 
    
         
            +
                          JSON.parse(resp)
         
     | 
| 
      
 152 
     | 
    
         
            +
                        )
         
     | 
| 
      
 153 
     | 
    
         
            +
                      expect(resp).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
      
 154 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 155 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPCreated)
         
     | 
| 
      
 156 
     | 
    
         
            +
                    end
         
     | 
| 
      
 157 
     | 
    
         
            +
                  end
         
     | 
| 
      
 158 
     | 
    
         
            +
             
     | 
| 
      
 159 
     | 
    
         
            +
                  it '#get_segments' do
         
     | 
| 
      
 160 
     | 
    
         
            +
                    @client.get_segments do |resp, req, res|
         
     | 
| 
      
 161 
     | 
    
         
            +
                      resp =
         
     | 
| 
      
 162 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Segments.create_segments(
         
     | 
| 
      
 163 
     | 
    
         
            +
                          JSON.parse(resp)
         
     | 
| 
      
 164 
     | 
    
         
            +
                        )
         
     | 
| 
      
 165 
     | 
    
         
            +
                      expect(resp).to be_a(SendGrid4r::REST::Contacts::Segments::Segments)
         
     | 
| 
      
 166 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 167 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPOK)
         
     | 
| 
      
 168 
     | 
    
         
            +
                    end
         
     | 
| 
      
 169 
     | 
    
         
            +
                  end
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                  it '#get_segment' do
         
     | 
| 
      
 172 
     | 
    
         
            +
                    @client.get_segment(@segment1.id) do |resp, req, res|
         
     | 
| 
      
 173 
     | 
    
         
            +
                      resp =
         
     | 
| 
      
 174 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Segments.create_segment(
         
     | 
| 
      
 175 
     | 
    
         
            +
                          JSON.parse(resp)
         
     | 
| 
      
 176 
     | 
    
         
            +
                        )
         
     | 
| 
      
 177 
     | 
    
         
            +
                      expect(resp).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
      
 178 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 179 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPOK)
         
     | 
| 
      
 180 
     | 
    
         
            +
                    end
         
     | 
| 
      
 181 
     | 
    
         
            +
                  end
         
     | 
| 
      
 182 
     | 
    
         
            +
             
     | 
| 
      
 183 
     | 
    
         
            +
                  it '#put_segment' do
         
     | 
| 
      
 184 
     | 
    
         
            +
                    pending 'waiting sendgrid documentation update'
         
     | 
| 
       69 
185 
     | 
    
         
             
                    edit_params = @segment_factory.create(
         
     | 
| 
       70 
     | 
    
         
            -
                      name: @ 
     | 
| 
      
 186 
     | 
    
         
            +
                      name: @edit_name1, conditions: [@condition]
         
     | 
| 
       71 
187 
     | 
    
         
             
                    )
         
     | 
| 
       72 
     | 
    
         
            -
                     
     | 
| 
       73 
     | 
    
         
            -
             
     | 
| 
       74 
     | 
    
         
            -
             
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                      expect(
         
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
                      ).to  
     | 
| 
      
 188 
     | 
    
         
            +
                    @client.put_segment(@segment1.id, edit_params) do |resp, req, res|
         
     | 
| 
      
 189 
     | 
    
         
            +
                      resp =
         
     | 
| 
      
 190 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Segments.create_segment(
         
     | 
| 
      
 191 
     | 
    
         
            +
                          JSON.parse(resp)
         
     | 
| 
      
 192 
     | 
    
         
            +
                        )
         
     | 
| 
      
 193 
     | 
    
         
            +
                      expect(resp).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
      
 194 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 195 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPOK)
         
     | 
| 
      
 196 
     | 
    
         
            +
                    end
         
     | 
| 
      
 197 
     | 
    
         
            +
                  end
         
     | 
| 
      
 198 
     | 
    
         
            +
             
     | 
| 
      
 199 
     | 
    
         
            +
                  it '#get_recipients_from_segment' do
         
     | 
| 
      
 200 
     | 
    
         
            +
                    @client.get_recipients_from_segment(@segment1.id) do |resp, req, res|
         
     | 
| 
      
 201 
     | 
    
         
            +
                      resp =
         
     | 
| 
      
 202 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Recipients.create_recipients(
         
     | 
| 
      
 203 
     | 
    
         
            +
                          JSON.parse(resp)
         
     | 
| 
      
 204 
     | 
    
         
            +
                        )
         
     | 
| 
      
 205 
     | 
    
         
            +
                      expect(resp).to be_a(
         
     | 
| 
      
 206 
     | 
    
         
            +
                        SendGrid4r::REST::Contacts::Recipients::Recipients
         
     | 
| 
      
 207 
     | 
    
         
            +
                      )
         
     | 
| 
      
 208 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 209 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPOK)
         
     | 
| 
      
 210 
     | 
    
         
            +
                    end
         
     | 
| 
      
 211 
     | 
    
         
            +
                  end
         
     | 
| 
      
 212 
     | 
    
         
            +
             
     | 
| 
      
 213 
     | 
    
         
            +
                  it '#delete_segment' do
         
     | 
| 
      
 214 
     | 
    
         
            +
                    @client.delete_segment(@segment1.id) do |resp, req, res|
         
     | 
| 
      
 215 
     | 
    
         
            +
                      expect(resp).to eq('')
         
     | 
| 
      
 216 
     | 
    
         
            +
                      expect(req).to be_a(RestClient::Request)
         
     | 
| 
      
 217 
     | 
    
         
            +
                      expect(res).to be_a(Net::HTTPNoContent)
         
     | 
| 
       80 
218 
     | 
    
         
             
                    end
         
     | 
| 
       81 
     | 
    
         
            -
                    # delete the segment
         
     | 
| 
       82 
     | 
    
         
            -
                    @client.delete_segment(new_segment.id)
         
     | 
| 
       83 
     | 
    
         
            -
                    expect do
         
     | 
| 
       84 
     | 
    
         
            -
                      @client.get_segment(new_segment.id)
         
     | 
| 
       85 
     | 
    
         
            -
                    end.to raise_error(RestClient::ResourceNotFound)
         
     | 
| 
       86 
     | 
    
         
            -
                  rescue => e
         
     | 
| 
       87 
     | 
    
         
            -
                    puts e.inspect
         
     | 
| 
       88 
     | 
    
         
            -
                    raise e
         
     | 
| 
       89 
219 
     | 
    
         
             
                  end
         
     | 
| 
       90 
220 
     | 
    
         
             
                end
         
     | 
| 
      
 221 
     | 
    
         
            +
              end
         
     | 
| 
       91 
222 
     | 
    
         | 
| 
      
 223 
     | 
    
         
            +
              describe 'unit test' do
         
     | 
| 
       92 
224 
     | 
    
         
             
                it 'creates condition instance' do
         
     | 
| 
       93 
225 
     | 
    
         
             
                  json =
         
     | 
| 
       94 
226 
     | 
    
         
             
                    '{'\
         
     | 
| 
         @@ -99,6 +231,7 @@ describe 'SendGrid4r::REST::Contacts::Segments' do 
     | 
|
| 
       99 
231 
     | 
    
         
             
                    '}'
         
     | 
| 
       100 
232 
     | 
    
         
             
                  hash = JSON.parse(json)
         
     | 
| 
       101 
233 
     | 
    
         
             
                  actual = SendGrid4r::REST::Contacts::Segments.create_condition(hash)
         
     | 
| 
      
 234 
     | 
    
         
            +
                  expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Condition)
         
     | 
| 
       102 
235 
     | 
    
         
             
                  expect(actual.field).to eq('last_name')
         
     | 
| 
       103 
236 
     | 
    
         
             
                  expect(actual.value).to eq('Miller')
         
     | 
| 
       104 
237 
     | 
    
         
             
                  expect(actual.operator).to eq('eq')
         
     | 
| 
         @@ -123,18 +256,17 @@ describe 'SendGrid4r::REST::Contacts::Segments' do 
     | 
|
| 
       123 
256 
     | 
    
         
             
                    '}'
         
     | 
| 
       124 
257 
     | 
    
         
             
                  hash = JSON.parse(json)
         
     | 
| 
       125 
258 
     | 
    
         
             
                  actual = SendGrid4r::REST::Contacts::Segments.create_segment(hash)
         
     | 
| 
      
 259 
     | 
    
         
            +
                  expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
       126 
260 
     | 
    
         
             
                  expect(actual.id).to eq(1)
         
     | 
| 
       127 
261 
     | 
    
         
             
                  expect(actual.name).to eq('Last Name Miller')
         
     | 
| 
       128 
262 
     | 
    
         
             
                  expect(actual.list_id).to eq(nil)
         
     | 
| 
       129 
     | 
    
         
            -
                  expect(actual.conditions 
     | 
| 
      
 263 
     | 
    
         
            +
                  expect(actual.conditions).to be_a(Array)
         
     | 
| 
       130 
264 
     | 
    
         
             
                  actual.conditions.each do |condition|
         
     | 
| 
       131 
     | 
    
         
            -
                    expect(
         
     | 
| 
       132 
     | 
    
         
            -
                       
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                      )
         
     | 
| 
       135 
     | 
    
         
            -
                    ).to eq(true)
         
     | 
| 
      
 265 
     | 
    
         
            +
                    expect(condition).to be_a(
         
     | 
| 
      
 266 
     | 
    
         
            +
                      SendGrid4r::REST::Contacts::Segments::Condition
         
     | 
| 
      
 267 
     | 
    
         
            +
                    )
         
     | 
| 
       136 
268 
     | 
    
         
             
                  end
         
     | 
| 
       137 
     | 
    
         
            -
                  expect(actual.recipient_count).to  
     | 
| 
      
 269 
     | 
    
         
            +
                  expect(actual.recipient_count).to be_a(Fixnum)
         
     | 
| 
       138 
270 
     | 
    
         
             
                end
         
     | 
| 
       139 
271 
     | 
    
         | 
| 
       140 
272 
     | 
    
         
             
                it 'creates segments instance' do
         
     | 
| 
         @@ -159,11 +291,10 @@ describe 'SendGrid4r::REST::Contacts::Segments' do 
     | 
|
| 
       159 
291 
     | 
    
         
             
                    '}'
         
     | 
| 
       160 
292 
     | 
    
         
             
                  hash = JSON.parse(json)
         
     | 
| 
       161 
293 
     | 
    
         
             
                  actual = SendGrid4r::REST::Contacts::Segments.create_segments(hash)
         
     | 
| 
       162 
     | 
    
         
            -
                  expect(actual 
     | 
| 
      
 294 
     | 
    
         
            +
                  expect(actual).to be_a(SendGrid4r::REST::Contacts::Segments::Segments)
         
     | 
| 
      
 295 
     | 
    
         
            +
                  expect(actual.segments).to be_a(Array)
         
     | 
| 
       163 
296 
     | 
    
         
             
                  actual.segments.each do |segment|
         
     | 
| 
       164 
     | 
    
         
            -
                    expect(
         
     | 
| 
       165 
     | 
    
         
            -
                      segment.is_a?(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
       166 
     | 
    
         
            -
                    ).to eq(true)
         
     | 
| 
      
 297 
     | 
    
         
            +
                    expect(segment).to be_a(SendGrid4r::REST::Contacts::Segments::Segment)
         
     | 
| 
       167 
298 
     | 
    
         
             
                  end
         
     | 
| 
       168 
299 
     | 
    
         
             
                end
         
     | 
| 
       169 
300 
     | 
    
         
             
              end
         
     | 
| 
         @@ -1,19 +1,19 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe  
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe SendGrid4r::Factory::ConditionFactory do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'unit test' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                before do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  Dotenv.load
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @factory = SendGrid4r::Factory::ConditionFactory.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @expect = {}
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @expect[:field] = 'last_name'
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @expect[:value] = 'Miller'
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @expect[:operator] = 'eq'
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @expect[:and_or] = ''
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                it 'is full case' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                it 'specify all params' do
         
     | 
| 
       17 
17 
     | 
    
         
             
                  condition = @factory.create(
         
     | 
| 
       18 
18 
     | 
    
         
             
                    field: 'last_name',
         
     | 
| 
       19 
19 
     | 
    
         
             
                    value: 'Miller',
         
     | 
| 
         @@ -1,26 +1,26 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe  
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                   
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe SendGrid4r::Factory::SegmentFactory do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'unit test' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                before do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  Dotenv.load
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @segment_factory = SendGrid4r::Factory::SegmentFactory.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @condition_factory = SendGrid4r::Factory::ConditionFactory.new
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @condition = @condition_factory.create(
         
     | 
| 
      
 11 
     | 
    
         
            +
                    field: 'last_name',
         
     | 
| 
      
 12 
     | 
    
         
            +
                    value: 'Miller',
         
     | 
| 
      
 13 
     | 
    
         
            +
                    operator: 'eq',
         
     | 
| 
      
 14 
     | 
    
         
            +
                    and_or: '')
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @expect = {}
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @expect[:id] = nil
         
     | 
| 
      
 17 
     | 
    
         
            +
                  @expect[:name] = 'Last Name Miller'
         
     | 
| 
      
 18 
     | 
    
         
            +
                  @expect[:list_id] = nil
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @expect[:conditions] = [@condition]
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @expect[:recipient_count] = nil
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                it 'is full params case' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                it 'specify all params' do
         
     | 
| 
       24 
24 
     | 
    
         
             
                  segment = @segment_factory.create(
         
     | 
| 
       25 
25 
     | 
    
         
             
                    name: 'Last Name Miller', conditions: [@condition]
         
     | 
| 
       26 
26 
     | 
    
         
             
                  )
         
     | 
| 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # encoding: utf-8
         
     | 
| 
       2 
2 
     | 
    
         
             
            require File.dirname(__FILE__) + '/../spec_helper'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            describe  
     | 
| 
       5 
     | 
    
         
            -
               
     | 
| 
       6 
     | 
    
         
            -
                 
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe SendGrid4r::Factory::VersionFactory do
         
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'unit test' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                before do
         
     | 
| 
      
 7 
     | 
    
         
            +
                  Dotenv.load
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @factory = SendGrid4r::Factory::VersionFactory.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
       9 
10 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
              context 'always' do
         
     | 
| 
       11 
11 
     | 
    
         
             
                it 'is simple case' do
         
     | 
| 
       12 
12 
     | 
    
         
             
                  version = @factory.create(name: 'version_name')
         
     | 
| 
       13 
13 
     | 
    
         
             
                  expect(version.name).to eq('version_name')
         
     |