leadsquared 0.3.1 → 0.4.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/VERSION +1 -1
- data/leadsquared.gemspec +3 -3
- data/lib/leadsquared/lead.rb +12 -25
- data/spec/leadsquared/lead_spec.rb +11 -15
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 2f6b501ce8ab4dd1adaabda63f2751574be73d7e
         | 
| 4 | 
            +
              data.tar.gz: 27531c051ac257780361ed40225c0e2b35a4d21c
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ceccfe9f88311e7137cc9a325eb111af74c09daab7a4a7101511d23f3028b196ee57671ac334bd877e42a06268517e1f225f8c124864481af5a7322eb5ad80e4
         | 
| 7 | 
            +
              data.tar.gz: 69a6a08f3f3897f2f6f50b24e0d509e12f0d548076a50edcaed6de2ba4b89008b1972743b7924558e8aa606de0799174468782104f59890f0fbe884930a72616
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.4.0
         | 
    
        data/leadsquared.gemspec
    CHANGED
    
    | @@ -2,16 +2,16 @@ | |
| 2 2 | 
             
            # DO NOT EDIT THIS FILE DIRECTLY
         | 
| 3 3 | 
             
            # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
         | 
| 4 4 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 5 | 
            -
            # stub: leadsquared 0. | 
| 5 | 
            +
            # stub: leadsquared 0.4.0 ruby lib
         | 
| 6 6 |  | 
| 7 7 | 
             
            Gem::Specification.new do |s|
         | 
| 8 8 | 
             
              s.name = "leadsquared"
         | 
| 9 | 
            -
              s.version = "0. | 
| 9 | 
            +
              s.version = "0.4.0"
         | 
| 10 10 |  | 
| 11 11 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 12 12 | 
             
              s.require_paths = ["lib"]
         | 
| 13 13 | 
             
              s.authors = ["David Paluy"]
         | 
| 14 | 
            -
              s.date = "2015- | 
| 14 | 
            +
              s.date = "2015-12-04"
         | 
| 15 15 | 
             
              s.description = "Ruby framework for integration with Leadsquared. Leadsquared API: http://apidocs.leadsquared.com/"
         | 
| 16 16 | 
             
              s.email = "dpaluy@gmail.com"
         | 
| 17 17 | 
             
              s.extra_rdoc_files = [
         | 
    
        data/lib/leadsquared/lead.rb
    CHANGED
    
    | @@ -35,22 +35,15 @@ module Leadsquared | |
| 35 35 | 
             
                  handle_response response
         | 
| 36 36 | 
             
                end
         | 
| 37 37 |  | 
| 38 | 
            -
                def create_lead(email,  | 
| 38 | 
            +
                def create_lead(email, values_hash = {})
         | 
| 39 39 | 
             
                  url = url_with_service("Lead.Create")
         | 
| 40 40 | 
             
                  body = [
         | 
| 41 41 | 
             
                    {
         | 
| 42 42 | 
             
                      "Attribute": "EmailAddress",
         | 
| 43 43 | 
             
                      "Value": email
         | 
| 44 | 
            -
                    },
         | 
| 45 | 
            -
                    {
         | 
| 46 | 
            -
                      "Attribute": "FirstName",
         | 
| 47 | 
            -
                      "Value": first_name
         | 
| 48 | 
            -
                    },
         | 
| 49 | 
            -
                    {
         | 
| 50 | 
            -
                      "Attribute": "LastName",
         | 
| 51 | 
            -
                      "Value": last_name
         | 
| 52 44 | 
             
                    }
         | 
| 53 45 | 
             
                  ]
         | 
| 46 | 
            +
                  body += build_attributes values_hash
         | 
| 54 47 | 
             
                  response = connection.post(url, {}, body.to_json)
         | 
| 55 48 | 
             
                  parsed_response = handle_response response
         | 
| 56 49 | 
             
                  parsed_response["Message"]["Id"]
         | 
| @@ -58,36 +51,25 @@ module Leadsquared | |
| 58 51 |  | 
| 59 52 | 
             
                def update_lead(lead_id, values_hash = {})
         | 
| 60 53 | 
             
                  url = url_with_service("Lead.Update")
         | 
| 61 | 
            -
                  body = values_hash | 
| 54 | 
            +
                  body = build_attributes values_hash
         | 
| 62 55 | 
             
                  response = connection.post(url, {leadId: lead_id}, body.to_json)
         | 
| 63 56 | 
             
                  parsed_response = handle_response response
         | 
| 64 57 | 
             
                  parsed_response["Status"]
         | 
| 65 58 | 
             
                end
         | 
| 66 59 |  | 
| 67 | 
            -
                def create_or_update(email | 
| 60 | 
            +
                def create_or_update(email, values_hash = {})
         | 
| 68 61 | 
             
                  url = url_with_service("Lead.CreateOrUpdate")
         | 
| 69 62 | 
             
                  body = [
         | 
| 70 63 | 
             
                    {
         | 
| 71 64 | 
             
                      "Attribute": "EmailAddress",
         | 
| 72 65 | 
             
                      "Value": email
         | 
| 73 66 | 
             
                    },
         | 
| 74 | 
            -
                    {
         | 
| 75 | 
            -
                      "Attribute": "FirstName",
         | 
| 76 | 
            -
                      "Value": first_name
         | 
| 77 | 
            -
                    },
         | 
| 78 | 
            -
                    {
         | 
| 79 | 
            -
                      "Attribute": "LastName",
         | 
| 80 | 
            -
                      "Value": last_name
         | 
| 81 | 
            -
                    },
         | 
| 82 | 
            -
                    {
         | 
| 83 | 
            -
                      "Attribute": "Phone",
         | 
| 84 | 
            -
                      "Value": phone
         | 
| 85 | 
            -
                    },
         | 
| 86 67 | 
             
                    {
         | 
| 87 68 | 
             
                      "Attribute": "SearchBy",
         | 
| 88 | 
            -
                      "Value":  | 
| 69 | 
            +
                      "Value": "EmailAddress"
         | 
| 89 70 | 
             
                    }
         | 
| 90 71 | 
             
                  ]
         | 
| 72 | 
            +
                  body += build_attributes(values_hash)
         | 
| 91 73 | 
             
                  response = connection.post(url, {}, body.to_json)
         | 
| 92 74 | 
             
                  parsed_response = handle_response response
         | 
| 93 75 | 
             
                  parsed_response["Message"]["Id"]
         | 
| @@ -95,12 +77,17 @@ module Leadsquared | |
| 95 77 |  | 
| 96 78 | 
             
                def visitor_to_lead(prospect_id, values_hash = {})
         | 
| 97 79 | 
             
                  url = url_with_service("Lead.Convert")
         | 
| 98 | 
            -
                  body = values_hash | 
| 80 | 
            +
                  body = build_attributes(values_hash)
         | 
| 99 81 | 
             
                  response = connection.post(url, {leadId: prospect_id}, body.to_json)
         | 
| 100 82 | 
             
                  parsed_response = handle_response response
         | 
| 101 83 | 
             
                  parsed_response["Status"]
         | 
| 102 84 | 
             
                end
         | 
| 103 85 |  | 
| 86 | 
            +
                private
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                def build_attributes(values_hash)
         | 
| 89 | 
            +
                  values_hash.map {|key, val| {"Attribute" => key, "Value" => val} }
         | 
| 90 | 
            +
                end
         | 
| 104 91 | 
             
              end
         | 
| 105 92 |  | 
| 106 93 | 
             
            end
         | 
| @@ -6,6 +6,9 @@ describe Leadsquared::Lead do | |
| 6 6 | 
             
              let(:email) { "test@example.com" }
         | 
| 7 7 | 
             
              let(:first_name) { "Bob" }
         | 
| 8 8 | 
             
              let(:last_name) { "Zeiger" }
         | 
| 9 | 
            +
              let(:attributes) do
         | 
| 10 | 
            +
                {"FirstName" => first_name, "LastName" => last_name}
         | 
| 11 | 
            +
              end
         | 
| 9 12 |  | 
| 10 13 | 
             
              let(:invalid_response_body) do
         | 
| 11 14 | 
             
                {
         | 
| @@ -218,6 +221,10 @@ describe Leadsquared::Lead do | |
| 218 221 | 
             
                      "Attribute": "EmailAddress",
         | 
| 219 222 | 
             
                      "Value": email
         | 
| 220 223 | 
             
                    },
         | 
| 224 | 
            +
                    {
         | 
| 225 | 
            +
                      "Attribute": "SearchBy",
         | 
| 226 | 
            +
                      "Value": "EmailAddress"
         | 
| 227 | 
            +
                    },
         | 
| 221 228 | 
             
                    {
         | 
| 222 229 | 
             
                      "Attribute": "FirstName",
         | 
| 223 230 | 
             
                      "Value": first_name
         | 
| @@ -225,27 +232,16 @@ describe Leadsquared::Lead do | |
| 225 232 | 
             
                    {
         | 
| 226 233 | 
             
                      "Attribute": "LastName",
         | 
| 227 234 | 
             
                      "Value": last_name
         | 
| 228 | 
            -
                    },
         | 
| 229 | 
            -
                    {
         | 
| 230 | 
            -
                      "Attribute": "Phone",
         | 
| 231 | 
            -
                      "Value": nil
         | 
| 232 | 
            -
                    },
         | 
| 233 | 
            -
                    {
         | 
| 234 | 
            -
                      "Attribute": "SearchBy",
         | 
| 235 | 
            -
                      "Value": "EmailAddress"
         | 
| 236 235 | 
             
                    }
         | 
| 237 236 | 
             
                  ]
         | 
| 238 237 | 
             
                  end
         | 
| 238 | 
            +
             | 
| 239 239 | 
             
                  it "valid request" do
         | 
| 240 240 | 
             
                    expect(mock_connection).to receive(:post).with(url, {}, body.to_json).and_return valid_response
         | 
| 241 | 
            -
                    response = subject.create_or_update(email,  | 
| 241 | 
            +
                    response = subject.create_or_update(email, attributes)
         | 
| 242 242 | 
             
                    expect(response).to eq(success_response["Message"]["Id"])
         | 
| 243 243 | 
             
                  end
         | 
| 244 244 | 
             
                end
         | 
| 245 | 
            -
             | 
| 246 | 
            -
                describe "search by phone" do
         | 
| 247 | 
            -
                  pending "TODO"
         | 
| 248 | 
            -
                end
         | 
| 249 245 | 
             
              end
         | 
| 250 246 |  | 
| 251 247 | 
             
              describe "#create_lead" do
         | 
| @@ -278,14 +274,14 @@ describe Leadsquared::Lead do | |
| 278 274 |  | 
| 279 275 | 
             
                it "valid request with given params" do
         | 
| 280 276 | 
             
                  expect(mock_connection).to receive(:post).with(url, {}, body.to_json).and_return valid_response
         | 
| 281 | 
            -
                  response = subject.create_lead(email,  | 
| 277 | 
            +
                  response = subject.create_lead(email, attributes)
         | 
| 282 278 | 
             
                  expect(response).to eq(success_response["Message"]["Id"])
         | 
| 283 279 | 
             
                end
         | 
| 284 280 |  | 
| 285 281 | 
             
                it "invalid request" do
         | 
| 286 282 | 
             
                  expect(mock_connection).to receive(:post).with(url, {}, body.to_json).and_return invalid_response
         | 
| 287 283 | 
             
                  expect {
         | 
| 288 | 
            -
                    subject.create_lead(email,  | 
| 284 | 
            +
                    subject.create_lead(email, attributes)
         | 
| 289 285 | 
             
                  }.to raise_error(Leadsquared::InvalidRequestError)
         | 
| 290 286 | 
             
                end
         | 
| 291 287 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: leadsquared
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.4.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - David Paluy
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015- | 
| 11 | 
            +
            date: 2015-12-04 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |