outreach 0.1.0 → 0.1.1

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: fe1c9b5714bb38174c441cb266cd46381aa3110d
4
- data.tar.gz: b818c9939969cb205bcb7e86b76c7e7aa76817cb
3
+ metadata.gz: 728741869e2d409c8a9b36af355f44fcacf903b4
4
+ data.tar.gz: cb7a65b916ea0f68e377b920f760776e0a1348ae
5
5
  SHA512:
6
- metadata.gz: 6e6766d6f9a6095003e293b30605dc68087c61a47014130aae05aba290f5c949c3c54d39ec00df5771c1cae6dc452046a6f1a627439b8037b36c6cd8f8bdf0d7
7
- data.tar.gz: ffae74024011ff42c117d485811f663c31a75f7e8f05041f18b0353dc5f46c8fb782855bbbb97f7ce8d96f690edf1d26de40565b506223ca59ee5b6caefedae6
6
+ metadata.gz: fced1a8be302d3381f4a5c280541234baa28abf188ece3b19ad2c592bb0dc405cbda16cb3913e31bc13279544e64248775152d40213162a254d21343d51b0b8a
7
+ data.tar.gz: c370fa71c906cae340fe146fbad93b70564780a91d15d7fa442e77e33c428af794fb5994fd586f1e895907e4eae5d130834a5a5dbef22b6f291b94f07364e322
data/README.md CHANGED
@@ -20,7 +20,7 @@ And then execute:
20
20
 
21
21
  Or install it yourself as:
22
22
 
23
- $ gem install outrach
23
+ $ gem install outreach
24
24
 
25
25
  Set your api access with:
26
26
  ```ruby
@@ -3,23 +3,41 @@ module Outreach
3
3
  attr_accessor :first_name, :last_name, :company, :contact, :tags, :id
4
4
 
5
5
  def initialize(attrs)
6
- @first_name = attrs['attributes']['personal']['name']['first']
7
- @last_name = attrs['attributes']['personal']['name']['last']
8
- @company = to_ostruct(attrs['attributes']['company'])
9
- @contact = to_ostruct(attrs['attributes']['contact'])
10
- @tags = attrs['attributes']['metadata']['tags']
11
6
  @id = attrs['id']
7
+ @first_name = attrs['first_name']
8
+ @last_name = attrs['last_name']
9
+ @company = attrs['company']
10
+ @contact = attrs['contact']
11
+ @tags = attrs['tags']
12
+ end
13
+
14
+ def self.build_from_attributes_hash(attrs)
15
+ result = {}
16
+ result['first_name'] = nested_hash_value(attrs, ['attributes', 'personal',
17
+ 'name', 'first'])
18
+ result['last_name'] = nested_hash_value(attrs, ['attributes', 'personal',
19
+ 'name', 'last'])
20
+ result['company'] = to_ostruct(attrs['attributes'].fetch('company', {}))
21
+ result['contact'] = to_ostruct(attrs['attributes'].fetch('contact', {}))
22
+ result['tags'] = nested_hash_value(attrs, ['attributes', 'metadata',
23
+ 'tags'])
24
+ result['id'] = attrs['id']
25
+ new(result)
12
26
  end
13
27
 
14
28
  private
15
29
 
16
- def to_ostruct(hash)
30
+ def self.to_ostruct(hash)
17
31
  o = OpenStruct.new(hash)
18
32
  hash.each.with_object(o) do |(k,v), o|
19
33
  o.send(:"#{k}=", to_ostruct(v)) if v.is_a? Hash
20
34
  end
21
35
  o
22
36
  end
37
+
38
+ def self.nested_hash_value(attrs, keys)
39
+ keys.reduce(attrs) {|m,k| m && m[k] }
40
+ end
23
41
  end
24
42
  end
25
43
 
@@ -23,6 +23,12 @@ module Outreach
23
23
  parse_response(response, response_format)
24
24
  end
25
25
 
26
+ def patch(url, params)
27
+ response_format = params.delete(:response_format) || :json
28
+ response = HTTParty.patch(url, body: params.to_json, headers: auth_header)
29
+ parse_response(response, response_format)
30
+ end
31
+
26
32
  def delete(url)
27
33
  response = HTTParty.delete(url, headers: auth_header)
28
34
  parse_response(response)
@@ -7,12 +7,19 @@ module Outreach
7
7
 
8
8
  def find(id)
9
9
  response = @request.get("#{api_url}/#{id}")
10
- collection_class.new(response['data'])
10
+ collection_class.build_from_attributes_hash(response['data'])
11
11
  end
12
12
 
13
13
  def find_all(attrs={})
14
- response = @request.get(api_url, attribute_mapping(attrs))
15
- response['data'].map {|attrs| collection_class.new(attrs)}
14
+ response = @request.get(api_url, filter_attribute_mapping(attrs))
15
+ response['data'].map do |attrs|
16
+ collection_class.build_from_attributes_hash(attrs)
17
+ end
18
+ end
19
+
20
+ def update(id, attrs)
21
+ mapped_attrs = update_attribute_mapping(attrs)
22
+ @request.patch(api_url + "/" + id.to_s, mapped_attrs)
16
23
  end
17
24
 
18
25
  protected
@@ -25,7 +32,7 @@ module Outreach
25
32
  Outreach::Prospect
26
33
  end
27
34
 
28
- def attribute_mapping(attrs)
35
+ def filter_attribute_mapping(attrs)
29
36
  if attrs[:first_name]
30
37
  attrs["filter[personal/name/first]"] = attrs.delete(:first_name)
31
38
  end
@@ -38,6 +45,28 @@ module Outreach
38
45
  end
39
46
  attrs
40
47
  end
48
+
49
+ def update_attribute_mapping(attrs)
50
+ result = {
51
+ 'data' => {
52
+ 'attributes' => {
53
+ 'personal' => {},
54
+ 'contact' => {}
55
+ }
56
+ }
57
+ }
58
+
59
+ if attrs['first_name']
60
+ result['data']['attributes']['personal']['name']['first'] = attrs['first_name']
61
+ end
62
+ if attrs['last_name']
63
+ result['data']['attributes']['personal']['name']['last'] = attrs['last_name']
64
+ end
65
+ if attrs['email']
66
+ result['data']['attributes']['contact']['email'] = attrs['email']
67
+ end
68
+ result
69
+ end
41
70
  end
42
71
  end
43
72
  end
@@ -1,3 +1,3 @@
1
1
  module Outreach
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/outreach.gemspec CHANGED
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "rspec", "~> 3.4"
24
24
  spec.add_development_dependency "webmock", "~> 1.24"
25
+ spec.add_development_dependency "byebug"
25
26
 
26
27
  spec.add_dependency "httparty", "~> 0.13"
27
28
  spec.add_dependency "json", "~> 1.8"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outreach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris O'Sullivan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-04 00:00:00.000000000 Z
11
+ date: 2016-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.24'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: httparty
71
85
  requirement: !ruby/object:Gem::Requirement