contact-data 0.0.3 → 0.0.4
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/Gemfile.lock +1 -1
- data/lib/contact-data/deprecated.rb +9 -1
- data/lib/contact-data/fetcher.rb +33 -7
- data/lib/contact-data/version.rb +1 -1
- data/spec/contact-data_deprecated_spec.rb +14 -1
- data/spec/contact-data_links_spec.rb +1 -1
- 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: ccca2c323f5abad769429ed05428c70aedd24235
         | 
| 4 | 
            +
              data.tar.gz: 858377cd0608ee09b456879fa3190a985795d133
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2d723b4917be853a4722b6fde3a33917295f1096b28e3f737445709762a71c8a213a484739c7c46d0b38c1b3bbf099f9ba16ee896d57feb3e7749c08bfd109d9
         | 
| 7 | 
            +
              data.tar.gz: 32142ae429319eb2ce8c6ae78fb6e9f391759cd422275d574e9de387d6e6cb14c2edfc0e08a011aaa399a0e017696ef631a9d1ebe0007dc0dd7d112ee1ce169a
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -3,7 +3,15 @@ class ContactData | |
| 3 3 | 
             
              class Deprecated
         | 
| 4 4 | 
             
                class << self
         | 
| 5 5 | 
             
                  def search(name)
         | 
| 6 | 
            -
                    Fetcher.get("name/#{name} | 
| 6 | 
            +
                    Fetcher.get("name/#{name}")
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                  def find_contacts_in(text)
         | 
| 10 | 
            +
                    Fetcher.post('text/find_contacts', payload: {text: text})
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  def link_metadata(url)
         | 
| 14 | 
            +
                    Fetcher.get("link/#{CGI::escape(url)}", :noformat => true)
         | 
| 7 15 | 
             
                  end
         | 
| 8 16 | 
             
                end
         | 
| 9 17 | 
             
              end
         | 
    
        data/lib/contact-data/fetcher.rb
    CHANGED
    
    | @@ -5,22 +5,48 @@ class ContactData | |
| 5 5 | 
             
                API = 'api/v2'
         | 
| 6 6 |  | 
| 7 7 | 
             
                class << self
         | 
| 8 | 
            -
                   | 
| 9 | 
            -
                     | 
| 10 | 
            -
            puts  | 
| 11 | 
            -
             | 
| 8 | 
            +
                  [:get, :post].each do |http_method|
         | 
| 9 | 
            +
                    define_method(http_method) do |api_method, options = {}|
         | 
| 10 | 
            +
            puts options # debug
         | 
| 11 | 
            +
                      url = get_url_from(api_method, options)
         | 
| 12 | 
            +
                      fetch_and_parse url, http_method, options
         | 
| 13 | 
            +
                    end
         | 
| 12 14 | 
             
                  end
         | 
| 13 15 |  | 
| 14 16 | 
             
                  private
         | 
| 15 17 |  | 
| 16 18 | 
             
                  def get_url_from(api_method, options = {})
         | 
| 17 19 | 
             
                    if api_method.is_a?(String)
         | 
| 18 | 
            -
                      URI.escape("#{URL}/#{api_method}")
         | 
| 20 | 
            +
                      url = URI.escape("#{URL}/#{api_method}")
         | 
| 19 21 | 
             
                    elsif options[:base]
         | 
| 20 | 
            -
                      "#{URL}/#{API}/#{options[:base]}/#{api_method}"
         | 
| 22 | 
            +
                      url = "#{URL}/#{API}/#{options[:base]}/#{api_method}"
         | 
| 21 23 | 
             
                    else
         | 
| 22 | 
            -
                      "#{URL}/#{API}/#{api_method}"
         | 
| 24 | 
            +
                      url = "#{URL}/#{API}/#{api_method}"
         | 
| 23 25 | 
             
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    if options[:noformat]
         | 
| 28 | 
            +
                      url
         | 
| 29 | 
            +
                    else
         | 
| 30 | 
            +
                      format = options[:format] || :json
         | 
| 31 | 
            +
                      "#{url}.#{format}"
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  def fetch_and_parse(url, method = :get, options = {})
         | 
| 36 | 
            +
                    json = fetch(url, method, options)
         | 
| 37 | 
            +
                    parse json
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def fetch(url, method = :get, options = {})
         | 
| 41 | 
            +
                    args = { url: url, method: method }
         | 
| 42 | 
            +
                    args[:headers] = { params: options[:params] } if options.key? :params
         | 
| 43 | 
            +
                    args[:payload] = options[:payload] if options.key? :payload
         | 
| 44 | 
            +
            puts args # setup
         | 
| 45 | 
            +
                    RestClient::Request.new(args).execute
         | 
| 46 | 
            +
                  end
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  def parse(json)
         | 
| 49 | 
            +
                    JSON.parse(json, symbolize_names: true, allow_nan: true)
         | 
| 24 50 | 
             
                  end
         | 
| 25 51 | 
             
                end
         | 
| 26 52 | 
             
              end
         | 
    
        data/lib/contact-data/version.rb
    CHANGED
    
    
| @@ -7,6 +7,19 @@ describe ContactData::Deprecated do | |
| 7 7 |  | 
| 8 8 | 
             
              it 'searches for a contact by name' do
         | 
| 9 9 | 
             
                result = ContactData::Deprecated.search(name)
         | 
| 10 | 
            -
                expect(result).to be_a( | 
| 10 | 
            +
                expect(result).to be_a(Hash)
         | 
| 11 | 
            +
              end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              it 'finds contact names in text' do
         | 
| 14 | 
            +
                text = 'lorem ipsum john smith dolor sit amet'
         | 
| 15 | 
            +
                result = ContactData::Deprecated.find_contacts_in(text)
         | 
| 16 | 
            +
                expect(result).to be_a(Hash)
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              it 'finds information about a url' do
         | 
| 20 | 
            +
                url = 'http://www.iana.org/numbers'
         | 
| 21 | 
            +
                result = ContactData::Deprecated.link_metadata(url)
         | 
| 22 | 
            +
            puts result # debug
         | 
| 23 | 
            +
                expect(result).to be_a(Hash)
         | 
| 11 24 | 
             
              end
         | 
| 12 25 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: contact-data
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Xenapto
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2014-06- | 
| 11 | 
            +
            date: 2014-06-08 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rest-client
         |