contact-data 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e60c22aaf663f59e740c8130dd7227160d7e0bb4
4
- data.tar.gz: 263f67f6c10234ca33f7f7e4cb35c9f08e6630a7
3
+ metadata.gz: ccca2c323f5abad769429ed05428c70aedd24235
4
+ data.tar.gz: 858377cd0608ee09b456879fa3190a985795d133
5
5
  SHA512:
6
- metadata.gz: 1fb01b732100d702436e31889a7eb70ff712d8d42e0347746e7fa8b067e7355725a97ff83c5420276e7a16c256a31460bed3a599cbf0844c0b55331b1312b5ab
7
- data.tar.gz: fa7434dfd6ac0e1482b5dc39828b1f8522f25f6b9ffb71712a9037c72a80f3251db6d8bf8b703ce5a01c28422b468178b73cf8d59a26974ae83694589c5cbd64
6
+ metadata.gz: 2d723b4917be853a4722b6fde3a33917295f1096b28e3f737445709762a71c8a213a484739c7c46d0b38c1b3bbf099f9ba16ee896d57feb3e7749c08bfd109d9
7
+ data.tar.gz: 32142ae429319eb2ce8c6ae78fb6e9f391759cd422275d574e9de387d6e6cb14c2edfc0e08a011aaa399a0e017696ef631a9d1ebe0007dc0dd7d112ee1ce169a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- contact-data (0.0.1)
4
+ contact-data (0.0.3)
5
5
  rest-client (~> 1)
6
6
 
7
7
  GEM
@@ -3,7 +3,15 @@ class ContactData
3
3
  class Deprecated
4
4
  class << self
5
5
  def search(name)
6
- Fetcher.get("name/#{name}.json")
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
@@ -5,22 +5,48 @@ class ContactData
5
5
  API = 'api/v2'
6
6
 
7
7
  class << self
8
- def get(api_method, options = {})
9
- url = get_url_from(api_method, options)
10
- puts url # debug
11
- RestClient.get url, options[:params]
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
@@ -1,3 +1,3 @@
1
1
  class ContactData
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -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(String)
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
@@ -5,6 +5,6 @@ require 'contact-data'
5
5
  describe ContactData::Links do
6
6
  it 'gets latest links with related slug' do
7
7
  result = ContactData::Links.latest
8
- expect(result).to be_a(String)
8
+ expect(result).to be_an(Array)
9
9
  end
10
10
  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.3
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-07 00:00:00.000000000 Z
11
+ date: 2014-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client