linkedin_v2 1.0.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 +7 -0
- data/.gitignore +11 -0
- data/.reek.yml +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +1175 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +135 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/linkedin_v2/api/medias.rb +15 -0
- data/lib/linkedin_v2/api/organizations.rb +41 -0
- data/lib/linkedin_v2/api/profiles.rb +32 -0
- data/lib/linkedin_v2/client.rb +18 -0
- data/lib/linkedin_v2/error.rb +16 -0
- data/lib/linkedin_v2/files/creator.rb +12 -0
- data/lib/linkedin_v2/files/destroyer.rb +12 -0
- data/lib/linkedin_v2/files/reader.rb +11 -0
- data/lib/linkedin_v2/helpers/attribute.rb +11 -0
- data/lib/linkedin_v2/helpers/handler.rb +25 -0
- data/lib/linkedin_v2/helpers/hash.rb +25 -0
- data/lib/linkedin_v2/helpers/url.rb +15 -0
- data/lib/linkedin_v2/templates/endpoints/company.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/logo.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/me.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/organizations.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/shares.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/ugc_post.erb +1 -0
- data/lib/linkedin_v2/templates/endpoints/upload_image.erb +1 -0
- data/lib/linkedin_v2/templates/payloads/base.rb +19 -0
- data/lib/linkedin_v2/templates/payloads/shares.rb +99 -0
- data/lib/linkedin_v2/templates/payloads/ugc_post.rb +76 -0
- data/lib/linkedin_v2/url/builder.rb +56 -0
- data/lib/linkedin_v2/url/response.rb +17 -0
- data/lib/linkedin_v2/version.rb +3 -0
- data/lib/linkedin_v2.rb +28 -0
- data/linkedin_v2.gemspec +48 -0
- metadata +250 -0
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.6.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
linkedin_v2 (1.0.0)
|
5
|
+
down (~> 4.8, >= 4.8.1)
|
6
|
+
rest-client (~> 2.0, >= 2.0.2)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.6.0)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
ast (2.4.0)
|
14
|
+
axiom-types (0.1.1)
|
15
|
+
descendants_tracker (~> 0.0.4)
|
16
|
+
ice_nine (~> 0.11.0)
|
17
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
18
|
+
codeclimate-engine-rb (0.4.1)
|
19
|
+
virtus (~> 1.0)
|
20
|
+
coderay (1.1.2)
|
21
|
+
coercible (1.0.0)
|
22
|
+
descendants_tracker (~> 0.0.1)
|
23
|
+
coveralls (0.8.23)
|
24
|
+
json (>= 1.8, < 3)
|
25
|
+
simplecov (~> 0.16.1)
|
26
|
+
term-ansicolor (~> 1.3)
|
27
|
+
thor (>= 0.19.4, < 2.0)
|
28
|
+
tins (~> 1.6)
|
29
|
+
crack (0.4.3)
|
30
|
+
safe_yaml (~> 1.0.0)
|
31
|
+
descendants_tracker (0.0.4)
|
32
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
33
|
+
diff-lcs (1.3)
|
34
|
+
docile (1.3.2)
|
35
|
+
domain_name (0.5.20190701)
|
36
|
+
unf (>= 0.0.5, < 1.0.0)
|
37
|
+
down (4.8.1)
|
38
|
+
addressable (~> 2.5)
|
39
|
+
equalizer (0.0.11)
|
40
|
+
hashdiff (1.0.0)
|
41
|
+
http-cookie (1.0.3)
|
42
|
+
domain_name (~> 0.5)
|
43
|
+
ice_nine (0.11.2)
|
44
|
+
jaro_winkler (1.5.3)
|
45
|
+
json (2.2.0)
|
46
|
+
kwalify (0.7.2)
|
47
|
+
method_source (0.9.2)
|
48
|
+
mime-types (3.2.2)
|
49
|
+
mime-types-data (~> 3.2015)
|
50
|
+
mime-types-data (3.2019.0331)
|
51
|
+
netrc (0.11.0)
|
52
|
+
parallel (1.17.0)
|
53
|
+
parser (2.6.3.0)
|
54
|
+
ast (~> 2.4.0)
|
55
|
+
pry (0.12.2)
|
56
|
+
coderay (~> 1.1.0)
|
57
|
+
method_source (~> 0.9.0)
|
58
|
+
psych (3.1.0)
|
59
|
+
public_suffix (3.1.1)
|
60
|
+
rainbow (3.0.0)
|
61
|
+
rake (10.5.0)
|
62
|
+
reek (5.4.0)
|
63
|
+
codeclimate-engine-rb (~> 0.4.0)
|
64
|
+
kwalify (~> 0.7.0)
|
65
|
+
parser (>= 2.5.0.0, < 2.7, != 2.5.1.1)
|
66
|
+
psych (~> 3.1.0)
|
67
|
+
rainbow (>= 2.0, < 4.0)
|
68
|
+
rest-client (2.0.2)
|
69
|
+
http-cookie (>= 1.0.2, < 2.0)
|
70
|
+
mime-types (>= 1.16, < 4.0)
|
71
|
+
netrc (~> 0.8)
|
72
|
+
rspec (3.8.0)
|
73
|
+
rspec-core (~> 3.8.0)
|
74
|
+
rspec-expectations (~> 3.8.0)
|
75
|
+
rspec-mocks (~> 3.8.0)
|
76
|
+
rspec-core (3.8.2)
|
77
|
+
rspec-support (~> 3.8.0)
|
78
|
+
rspec-expectations (3.8.4)
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
+
rspec-support (~> 3.8.0)
|
81
|
+
rspec-mocks (3.8.1)
|
82
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
+
rspec-support (~> 3.8.0)
|
84
|
+
rspec-support (3.8.2)
|
85
|
+
rubocop (0.73.0)
|
86
|
+
jaro_winkler (~> 1.5.1)
|
87
|
+
parallel (~> 1.10)
|
88
|
+
parser (>= 2.6)
|
89
|
+
rainbow (>= 2.2.2, < 4.0)
|
90
|
+
ruby-progressbar (~> 1.7)
|
91
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
92
|
+
ruby-progressbar (1.10.1)
|
93
|
+
safe_yaml (1.0.5)
|
94
|
+
simplecov (0.16.1)
|
95
|
+
docile (~> 1.1)
|
96
|
+
json (>= 1.8, < 3)
|
97
|
+
simplecov-html (~> 0.10.0)
|
98
|
+
simplecov-html (0.10.2)
|
99
|
+
term-ansicolor (1.7.1)
|
100
|
+
tins (~> 1.0)
|
101
|
+
thor (0.20.3)
|
102
|
+
thread_safe (0.3.6)
|
103
|
+
tins (1.21.1)
|
104
|
+
unf (0.1.4)
|
105
|
+
unf_ext
|
106
|
+
unf_ext (0.0.7.6)
|
107
|
+
unicode-display_width (1.6.0)
|
108
|
+
vcr (5.0.0)
|
109
|
+
virtus (1.0.5)
|
110
|
+
axiom-types (~> 0.1)
|
111
|
+
coercible (~> 1.0)
|
112
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
113
|
+
equalizer (~> 0.0, >= 0.0.9)
|
114
|
+
webmock (3.6.0)
|
115
|
+
addressable (>= 2.3.6)
|
116
|
+
crack (>= 0.3.2)
|
117
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
118
|
+
|
119
|
+
PLATFORMS
|
120
|
+
ruby
|
121
|
+
|
122
|
+
DEPENDENCIES
|
123
|
+
bundler (~> 2.0)
|
124
|
+
coveralls (~> 0.8.23)
|
125
|
+
linkedin_v2!
|
126
|
+
pry (~> 0.12.2)
|
127
|
+
rake (~> 10.0)
|
128
|
+
reek (~> 5.4)
|
129
|
+
rspec (~> 3.0)
|
130
|
+
rubocop (~> 0.73.0)
|
131
|
+
vcr (~> 5.0)
|
132
|
+
webmock (~> 3.6)
|
133
|
+
|
134
|
+
BUNDLED WITH
|
135
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Lucas Teles
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# LinkedinV2
|
2
|
+
Ruby wrapper for the [V2 LinkedIn API](https://docs.microsoft.com/en-us/linkedin/consumer/integrations/self-serve/sign-in-with-linkedin?context=linkedin/consumer/context). The LinkedinV2 gem provides an easy-to-use wrapper for some LinkedIn's REST APIs.
|
3
|
+
|
4
|
+
[](https://coveralls.io/github/rockcontent/linkedin-api-v2?branch=add_coveralls)
|
5
|
+
[](https://travis-ci.org/rockcontent/linkedin-api-v2)
|
6
|
+
[](https://app.codacy.com/app/lucasteles22/linkedin-api-v2?utm_source=github.com&utm_medium=referral&utm_content=rockcontent/linkedin-api-v2&utm_campaign=Badge_Grade_Settings)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'linkedin_v2'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```shell
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```shell
|
25
|
+
$ gem install linkedin_v2
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Check our wiki [here](https://github.com/rockcontent/linkedin-api-v2/wiki)
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at [here](https://github.com/rockcontent/linkedin-api-v2).
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "linkedin_v2"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Api
|
3
|
+
module Medias
|
4
|
+
def upload_image(picture_url:)
|
5
|
+
file = Files::Creator.(picture_url)
|
6
|
+
body = { file: file }
|
7
|
+
path = LinkedinV2::Url::Builder.(:upload_image)
|
8
|
+
|
9
|
+
request(:post, path, body, {}, API_V1_URL)
|
10
|
+
ensure
|
11
|
+
Files::Destroyer.(file)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Api
|
3
|
+
module Organizations
|
4
|
+
ORGANIZATION_ENTITY = "organization".freeze
|
5
|
+
|
6
|
+
# Retrieve information about organizations
|
7
|
+
# https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-access-control
|
8
|
+
def organizations(projection: nil, start: nil, count: nil)
|
9
|
+
params = { projection: projection, start: start, count: count }
|
10
|
+
path = LinkedinV2::Url::Builder.(:organizations, params)
|
11
|
+
|
12
|
+
request(:get, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Retrieve Organization Logos and Cover Photos
|
16
|
+
# https://docs.microsoft.com/en-us/linkedin/marketing/integrations/community-management/organizations/organization-lookup-api#retrieve-organization-logos--cover-photos
|
17
|
+
def company_brand(identifier:, projection: nil)
|
18
|
+
params = { identifier: identifier, projection: projection }
|
19
|
+
path = LinkedinV2::Url::Builder.(:company, params)
|
20
|
+
|
21
|
+
request(:get, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_company_share(**options)
|
25
|
+
attrs = options.merge(entity: ORGANIZATION_ENTITY)
|
26
|
+
body = LinkedinV2::Templates::Payloads::Shares.new(attrs)
|
27
|
+
path = LinkedinV2::Url::Builder.(:shares)
|
28
|
+
|
29
|
+
request(:post, path, body.to_json, post_headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_company_post(**options)
|
33
|
+
attrs = options.merge(entity: ORGANIZATION_ENTITY)
|
34
|
+
body = LinkedinV2::Templates::Payloads::UgcPost.new(attrs)
|
35
|
+
path = LinkedinV2::Url::Builder.(:ugc_post)
|
36
|
+
|
37
|
+
request(:post, path, body.to_json, post_headers)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Api
|
3
|
+
module Profiles
|
4
|
+
PROFILE_ENTITY = "person".freeze
|
5
|
+
|
6
|
+
# Retrieve information about profile
|
7
|
+
# https://docs.microsoft.com/en-us/linkedin/shared/integrations/people/profile-api
|
8
|
+
def me(projection: nil)
|
9
|
+
params = { projection: projection }
|
10
|
+
path = LinkedinV2::Url::Builder.(:me, params)
|
11
|
+
|
12
|
+
request(:get, path)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_profile_share(**options)
|
16
|
+
attrs = options.merge(entity: PROFILE_ENTITY)
|
17
|
+
body = LinkedinV2::Templates::Payloads::Shares.new(attrs)
|
18
|
+
path = LinkedinV2::Url::Builder.(:shares)
|
19
|
+
|
20
|
+
request(:post, path, body.to_json, post_headers)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_profile_post(**options)
|
24
|
+
attrs = options.merge(entity: PROFILE_ENTITY)
|
25
|
+
body = LinkedinV2::Templates::Payloads::UgcPost.new(attrs)
|
26
|
+
path = LinkedinV2::Url::Builder.(:ugc_post)
|
27
|
+
|
28
|
+
request(:post, path, body.to_json, post_headers)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "api/organizations"
|
2
|
+
require_relative "api/profiles"
|
3
|
+
require_relative "api/medias"
|
4
|
+
|
5
|
+
module LinkedinV2
|
6
|
+
class Client
|
7
|
+
include LinkedinV2::Helpers::Handler
|
8
|
+
include LinkedinV2::Api::Organizations
|
9
|
+
include LinkedinV2::Api::Profiles
|
10
|
+
include LinkedinV2::Api::Medias
|
11
|
+
|
12
|
+
attr_reader :token
|
13
|
+
|
14
|
+
def initialize(token:)
|
15
|
+
@token = token
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :details
|
4
|
+
|
5
|
+
def initialize(msg = "", details:)
|
6
|
+
@details = details
|
7
|
+
super(msg)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# Url Builder error
|
12
|
+
InvalidEndpointError = Class.new(Error)
|
13
|
+
|
14
|
+
# LinkedIn response error
|
15
|
+
LinkedinResponseError = Class.new(Error)
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Helpers
|
3
|
+
module Handler
|
4
|
+
def request(method, endpoint, params = {}, additional_headers = {}, api = API_URL)
|
5
|
+
attrs = [ params, additional_headers ].reject(&:empty?)
|
6
|
+
|
7
|
+
JSON.parse(conn(api)[endpoint].public_send(method, *attrs))
|
8
|
+
rescue RestClient::ExceptionWithResponse => exception
|
9
|
+
raise LinkedinResponseError.new("response error", details: exception.response)
|
10
|
+
end
|
11
|
+
|
12
|
+
def conn(api)
|
13
|
+
RestClient::Resource.new(api, headers: headers)
|
14
|
+
end
|
15
|
+
|
16
|
+
def headers
|
17
|
+
{ "Authorization": "Bearer #{token}", "Content-Type": "application/json", }
|
18
|
+
end
|
19
|
+
|
20
|
+
def post_headers
|
21
|
+
{ "X-Restli-Protocol-Version": "2.0.0" }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Helpers
|
3
|
+
module Hash
|
4
|
+
class << self
|
5
|
+
def deep_merge(first, second)
|
6
|
+
first.merge(second.to_h, &merger)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def merger
|
12
|
+
-> (_key, first_value, second_value) {
|
13
|
+
if ::Hash === first_value && ::Hash === second_value
|
14
|
+
first_value.merge(second_value, &merger)
|
15
|
+
elsif ::Array === first_value && ::Array === second_value
|
16
|
+
first_value | second_value
|
17
|
+
else
|
18
|
+
[ :undefined, nil, :nil ].include?(second_value) ? first_value : second_value
|
19
|
+
end
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Helpers
|
3
|
+
module Url
|
4
|
+
class << self
|
5
|
+
# Escapes parameters hash on first level
|
6
|
+
def escape(**params)
|
7
|
+
params.inject({}) do |hash, (key, value)|
|
8
|
+
hash[key] = CGI::escape(value.to_s)
|
9
|
+
hash
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
/organizations/<%= identifier %>?projection=<%= projection %>
|
@@ -0,0 +1 @@
|
|
1
|
+
/organizations/<%= identifier %>?projection=(coverPhotoV2(original~:playableStreams,cropped~:playableStreams,cropInfo),logoV2(original~:playableStreams,cropped~:playableStreams,cropInfo))
|
@@ -0,0 +1 @@
|
|
1
|
+
/me?projection=<%= projection %>
|
@@ -0,0 +1 @@
|
|
1
|
+
/organizationalEntityAcls?q=roleAssignee&projection=<%= projection %>&start=<%= start %>&count=<%= count %>
|
@@ -0,0 +1 @@
|
|
1
|
+
/shares
|
@@ -0,0 +1 @@
|
|
1
|
+
/ugcPosts
|
@@ -0,0 +1 @@
|
|
1
|
+
/media/upload
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Templates
|
3
|
+
module Payloads
|
4
|
+
class Base
|
5
|
+
def initialize(**options)
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
raise NotImplementedError
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
attr_reader :options
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
module LinkedinV2
|
2
|
+
module Templates
|
3
|
+
module Payloads
|
4
|
+
class Shares < Base
|
5
|
+
def initialize(**options)
|
6
|
+
super(options)
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_json
|
10
|
+
payload.to_json
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def payload
|
16
|
+
response = body
|
17
|
+
if Helpers::Attribute.present?(description)
|
18
|
+
response = Helpers::Hash.deep_merge(response, description_attribute)
|
19
|
+
end
|
20
|
+
if Helpers::Attribute.present?(title)
|
21
|
+
response = Helpers::Hash.deep_merge(response, title_attribute)
|
22
|
+
end
|
23
|
+
|
24
|
+
response
|
25
|
+
end
|
26
|
+
|
27
|
+
def body
|
28
|
+
{
|
29
|
+
"owner" => "urn:li:#{entity}:#{identifier}",
|
30
|
+
"content" => {
|
31
|
+
"contentEntities" => [
|
32
|
+
{
|
33
|
+
"entityLocation" => url,
|
34
|
+
"thumbnails" => [
|
35
|
+
{
|
36
|
+
"resolvedUrl": thumbnail,
|
37
|
+
}
|
38
|
+
],
|
39
|
+
}
|
40
|
+
]
|
41
|
+
},
|
42
|
+
"distribution" => {
|
43
|
+
"linkedInDistributionTarget" => {}
|
44
|
+
},
|
45
|
+
"text" => {
|
46
|
+
"text" => text
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_reader :options
|
52
|
+
|
53
|
+
def entity
|
54
|
+
options.fetch(:entity)
|
55
|
+
end
|
56
|
+
|
57
|
+
def identifier
|
58
|
+
options.fetch(:identifier)
|
59
|
+
end
|
60
|
+
|
61
|
+
def url
|
62
|
+
options.fetch(:url)
|
63
|
+
end
|
64
|
+
|
65
|
+
def text
|
66
|
+
options.fetch(:text)
|
67
|
+
end
|
68
|
+
|
69
|
+
def thumbnail
|
70
|
+
options.fetch(:thumbnail, nil)
|
71
|
+
end
|
72
|
+
|
73
|
+
def title
|
74
|
+
options.fetch(:title, nil)
|
75
|
+
end
|
76
|
+
|
77
|
+
def description
|
78
|
+
options.fetch(:description, nil)
|
79
|
+
end
|
80
|
+
|
81
|
+
def description_attribute
|
82
|
+
{
|
83
|
+
"content" => {
|
84
|
+
"description" => description,
|
85
|
+
},
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def title_attribute
|
90
|
+
{
|
91
|
+
"content" => {
|
92
|
+
"title" => title,
|
93
|
+
},
|
94
|
+
}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|