social_nets_db 0.0.6 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/social_nets_db/db.yml +41 -11
- data/lib/social_nets_db/fn_validations.rb +33 -33
- data/lib/social_nets_db/social_net.rb +39 -16
- data/lib/social_nets_db/support.rb +9 -29
- data/lib/social_nets_db/tag_helper.rb +28 -28
- data/lib/social_nets_db/version.rb +1 -1
- data/lib/social_nets_db.rb +1 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d62ff42fff0c3a701d4440305f383f2ebe08c355e4d69348d1c7494da3caa4b
|
4
|
+
data.tar.gz: f9fe204e15d5bdf3df8ca3fa995f9b5457737d02e6946a5d9952fd191de14c2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77b51e953e43087f6389896957c7ea63a6cae82eaea5ab9c3700f068ee27fe563953b83fb77831d57e283b99b794615b87d751bf8d240c6e88e8250a35684d93
|
7
|
+
data.tar.gz: 2c148d72e0cc90f1cbd717cb1d231f246d5ee4ca78736b7aa998a1312ea27362e70f0e823db044502b426d637c931f1178180f63cf2c2dbc2628702670c8581d
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.0.9] - 2022-06-26
|
4
|
+
|
5
|
+
- Adds services
|
6
|
+
|
7
|
+
## [0.0.8] - 2022-01-02
|
8
|
+
|
9
|
+
- Adds services
|
10
|
+
|
11
|
+
## [0.0.7] - 2021-12-03
|
12
|
+
|
13
|
+
- Improves and corrects user page method
|
14
|
+
- Corrects .all method
|
15
|
+
- More documentation
|
16
|
+
|
3
17
|
## [0.0.6] - 2021-12-03
|
4
18
|
|
5
19
|
- Corrects data source of accessor methods
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -122,7 +122,7 @@ social_net = SocialNetsDB::SocialNet.find_by_uid("facebook")
|
|
122
122
|
Which are supported UIDs?
|
123
123
|
|
124
124
|
```ruby
|
125
|
-
SocialNetsDB.uids
|
125
|
+
SocialNetsDB::SocialNet.uids
|
126
126
|
#=> [
|
127
127
|
# "behance",
|
128
128
|
# "dribble",
|
@@ -253,7 +253,7 @@ model SocialNetAccount < ApplicationRecord
|
|
253
253
|
belongs_to :user
|
254
254
|
|
255
255
|
validates :account_id, presence: true, if: Proc.new { |record| record.username.blank? }
|
256
|
-
validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB.uids }
|
256
|
+
validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB::SocialNet.uids }
|
257
257
|
validates :username, presence: true, if: Proc.new { |record| record.account_id.blank? }
|
258
258
|
|
259
259
|
def social_net
|
data/lib/social_nets_db/db.yml
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
angellist:
|
2
|
+
name: AngelList Jobs
|
3
|
+
icons:
|
4
|
+
color: "#"
|
5
|
+
domain: angel.co
|
6
|
+
tags:
|
7
|
+
- recruiting
|
8
|
+
profile_url:
|
9
|
+
by_username: https://${domain}/u/${uid}
|
10
|
+
|
1
11
|
behance:
|
2
12
|
name: Behance
|
3
13
|
icons:
|
@@ -9,8 +19,8 @@ behance:
|
|
9
19
|
- design
|
10
20
|
- recruiting
|
11
21
|
profile_url:
|
12
|
-
by_username:
|
13
|
-
by_account_id:
|
22
|
+
by_username: https://${domain}/${uid}
|
23
|
+
by_account_id: https://${domain}/${uid}
|
14
24
|
|
15
25
|
bitchute:
|
16
26
|
name: Bitchute
|
@@ -53,7 +63,7 @@ discord:
|
|
53
63
|
tags:
|
54
64
|
- gaming
|
55
65
|
profile_url:
|
56
|
-
by_account_id:
|
66
|
+
by_account_id: https://discord.gg/${uid}
|
57
67
|
|
58
68
|
dribble:
|
59
69
|
name: Dribble
|
@@ -67,7 +77,7 @@ dribble:
|
|
67
77
|
- portfolio
|
68
78
|
profile_url:
|
69
79
|
by_username: https://${domain}/${uid}
|
70
|
-
by_account_id:
|
80
|
+
by_account_id: https://${domain}/${uid}
|
71
81
|
|
72
82
|
email:
|
73
83
|
name: E-mail
|
@@ -100,7 +110,7 @@ facebook:
|
|
100
110
|
- social net
|
101
111
|
profile_url:
|
102
112
|
by_username: https://${domain}/${uid}
|
103
|
-
by_account_id:
|
113
|
+
by_account_id: https://${domain}/${uid}
|
104
114
|
|
105
115
|
fl.ru:
|
106
116
|
name: FL
|
@@ -190,7 +200,7 @@ hh:
|
|
190
200
|
tags:
|
191
201
|
- recruiting
|
192
202
|
profile_url:
|
193
|
-
by_account_id:
|
203
|
+
by_account_id: https://${domain}/resume/${uid}
|
194
204
|
|
195
205
|
github:
|
196
206
|
name: GitHub
|
@@ -203,7 +213,7 @@ github:
|
|
203
213
|
- recruiting
|
204
214
|
profile_url:
|
205
215
|
by_username: https://${domain}/${uid}
|
206
|
-
by_account_id:
|
216
|
+
by_account_id: https://${domain}/${uid}
|
207
217
|
|
208
218
|
gitlab:
|
209
219
|
name: GitLab
|
@@ -217,6 +227,16 @@ gitlab:
|
|
217
227
|
profile_url:
|
218
228
|
by_username: https://${domain}/${uid}
|
219
229
|
|
230
|
+
indeed:
|
231
|
+
name: Indeed
|
232
|
+
icons:
|
233
|
+
color: "#003A9B"
|
234
|
+
domain: indeed.com
|
235
|
+
tags:
|
236
|
+
- recruiting
|
237
|
+
profile_url:
|
238
|
+
by_account_id: https://my.${domain}/p/${uid}
|
239
|
+
|
220
240
|
instagram:
|
221
241
|
name: Instagram
|
222
242
|
icons:
|
@@ -376,6 +396,16 @@ remoteok:
|
|
376
396
|
profile_url:
|
377
397
|
by_username: https://${domain}/@${uid}
|
378
398
|
|
399
|
+
revue:
|
400
|
+
name: Revue
|
401
|
+
icons:
|
402
|
+
color: "#E15718"
|
403
|
+
domain: getrevue.co
|
404
|
+
tags:
|
405
|
+
- blog
|
406
|
+
profile_url:
|
407
|
+
by_username: https://www.${domain}/profile/${uid}
|
408
|
+
|
379
409
|
rokfin:
|
380
410
|
name: Rokfin
|
381
411
|
icons:
|
@@ -409,7 +439,7 @@ stackoverflow:
|
|
409
439
|
- recruiting
|
410
440
|
- programming
|
411
441
|
profile_url:
|
412
|
-
by_account_id:
|
442
|
+
by_account_id: https://${domain}/users/${uid}?tab=profile
|
413
443
|
|
414
444
|
subscribestar:
|
415
445
|
name: SubscribeStar
|
@@ -476,7 +506,7 @@ upwork:
|
|
476
506
|
- freelancers
|
477
507
|
- programming
|
478
508
|
profile_url:
|
479
|
-
by_account_id:
|
509
|
+
by_account_id: https://${domain}/freelancers/~${uid}
|
480
510
|
|
481
511
|
vkontakte:
|
482
512
|
name: Вконтакте
|
@@ -488,7 +518,7 @@ vkontakte:
|
|
488
518
|
- social net
|
489
519
|
profile_url:
|
490
520
|
by_username: https://${domain}/${uid}
|
491
|
-
by_account_id:
|
521
|
+
by_account_id: https://${domain}/id${uid}
|
492
522
|
|
493
523
|
youtube:
|
494
524
|
name: YouTube
|
@@ -500,7 +530,7 @@ youtube:
|
|
500
530
|
- video-hosting
|
501
531
|
profile_url:
|
502
532
|
by_username: https://${domain}/c/${uid}
|
503
|
-
by_account_id:
|
533
|
+
by_account_id: https://${domain}/channel/${uid}
|
504
534
|
|
505
535
|
youtube_profile:
|
506
536
|
name: YouTube profile
|
@@ -2,44 +2,44 @@
|
|
2
2
|
|
3
3
|
module FnValidations
|
4
4
|
|
5
|
-
|
5
|
+
module_function
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
def validate_argument_type! argument, permitted_types
|
8
|
+
types = Array(permitted_types)
|
9
|
+
type_names = types.map { |klass| "`#{klass}`" }.join(" or ")
|
10
|
+
valid = types.any? { |type| argument.is_a? type }
|
11
|
+
message = "#{type_names} is expected, you pass a `#{argument.class}` (#{argument})"
|
12
|
+
fail TypeError, message unless valid
|
13
|
+
argument
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
def validate_collection_item_types! collection, permitted_types
|
17
|
+
types = Array(permitted_types)
|
18
|
+
type_names = types.map { |name| "`#{name}`" }.join(" or ")
|
19
|
+
valid = collection.all? { |item| types.include?(item.class) }
|
20
|
+
message = "#{type_names} is expected, one the items you pass is of incorrect type"
|
21
|
+
fail TypeError, message unless valid
|
22
|
+
collection
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
def validate_argument_boolean! argument
|
26
|
+
validate_argument_type! argument, [TrueClass, FalseClass]
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
def validate_argument_presence! argument
|
30
|
+
validate_argument_type! argument, [String, Symbol]
|
31
|
+
return argument if argument.is_a?(Symbol)
|
32
|
+
message = "You must pass a non-empty String, you are passing #{argument.inspect}"
|
33
|
+
fail ArgumentError, message unless argument.is_a?(String) && argument != ""
|
34
|
+
argument
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
def validate_argument_positive! argument
|
38
|
+
validate_argument_type! argument, Numeric
|
39
|
+
message = "You must pass a positive value, you pass #{argument.inspect}"
|
40
|
+
fail ArgumentError, message unless argument.positive?
|
41
|
+
argument
|
42
|
+
end
|
43
43
|
|
44
44
|
end
|
45
45
|
|
@@ -9,6 +9,9 @@ class SocialNetsDB
|
|
9
9
|
extend FnValidations
|
10
10
|
include FnValidations
|
11
11
|
|
12
|
+
# @param [String, Symbol] uid Social net UID (which must be among the top-level keys in db.yml)
|
13
|
+
# @param [Hash] data
|
14
|
+
#
|
12
15
|
def initialize(uid, data)
|
13
16
|
validate_argument_type! data, Hash
|
14
17
|
validate_argument_type! uid, [String, Symbol]
|
@@ -17,35 +20,46 @@ class SocialNetsDB
|
|
17
20
|
|
18
21
|
attr_accessor :uid
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
[:color, :domain, :icons, :name, :tags].each do |method_symbol|
|
24
|
+
define_method(method_symbol) do
|
25
|
+
fallback_value = method_symbol == :tags ? [] : nil
|
26
|
+
@data.fetch(method_symbol.to_s, fallback_value)
|
27
|
+
end
|
28
|
+
end
|
26
29
|
|
30
|
+
# @return [Hash] Raw data we have on the initialized social net
|
31
|
+
#
|
27
32
|
def to_h
|
28
33
|
self.class.send :raw_data_for, @uid
|
29
34
|
end
|
30
35
|
|
36
|
+
# @return [String] full URL of the social net
|
37
|
+
#
|
31
38
|
def url
|
32
39
|
"https://#{domain}"
|
33
40
|
end
|
34
41
|
|
42
|
+
# @return [String] full URL of user’s page in the social net
|
43
|
+
# @param [String, Symbol, Integer] username
|
44
|
+
# @param [String, Symbol, Integer] username
|
45
|
+
# @example
|
46
|
+
# SocialNetsDB::SocialNet.find("facebook").user_page(username: "dhh")
|
47
|
+
# #=> "https://facebook.com/dhh"
|
48
|
+
#
|
35
49
|
def user_page(username: nil, account_id: nil)
|
36
50
|
return unless page = to_h["profile_url"]
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(account_id)
|
45
|
-
template.sub("${domain}", domain.to_s).sub("${uid}", account_id)
|
51
|
+
fail(ArgumentError, "Either a username or an account id must be provided") if [username, account_id].none?
|
52
|
+
if username && page["by_username"]
|
53
|
+
validate_argument_type! username, [String, Symbol, Integer]
|
54
|
+
page["by_username"].sub("${domain}", domain.to_s).sub("${uid}", username.to_s)
|
55
|
+
elsif account_id && page["by_account_id"]
|
56
|
+
validate_argument_type! account_id, [String, Symbol, Integer]
|
57
|
+
page["by_account_id"].sub("${domain}", domain.to_s).sub("${uid}", account_id.to_s)
|
46
58
|
end
|
47
59
|
end
|
48
60
|
|
61
|
+
# @return [Array] available methods for bilding user page URL
|
62
|
+
#
|
49
63
|
def user_page_methods
|
50
64
|
["account_id", "username"].select { |key| present_str? to_h.dig("profile_url", "by_#{key}") }
|
51
65
|
end
|
@@ -56,12 +70,15 @@ class SocialNetsDB
|
|
56
70
|
class << self
|
57
71
|
|
58
72
|
# TODO this must be transofrmed into array of structs
|
73
|
+
# @return [Array<SocialNetsDB::SocialNet>] a list of all social nets initialized as objects
|
59
74
|
def all
|
60
|
-
RECORDS
|
75
|
+
RECORDS.map { |uid, data| new(uid, data) }
|
61
76
|
end
|
62
77
|
|
78
|
+
|
63
79
|
# @param [String] name Social network name
|
64
80
|
# @param [String, Symbol] uid Social network UID
|
81
|
+
# @return [SocialNetsDB::SocialNet, nil]
|
65
82
|
#
|
66
83
|
def find_by(name: nil, uid: nil)
|
67
84
|
return find_by_uid(uid) if present_str?(uid)
|
@@ -69,13 +86,19 @@ class SocialNetsDB
|
|
69
86
|
fail ArgumentError, "`name:` or `uid:` must be provided. You are passing name: #{name.inspect}, uid: #{uid.inspect}"
|
70
87
|
end
|
71
88
|
|
89
|
+
|
90
|
+
# @param [String] name Social network name
|
91
|
+
# @return [SocialNetsDB::SocialNet, nil]
|
92
|
+
#
|
72
93
|
def find_by_name(name)
|
73
94
|
validate_argument_presence! name
|
74
95
|
return unless record = RECORDS.select { |uid, data| data["name"] == name }.first
|
75
96
|
find_by_uid record[0]
|
76
97
|
end
|
77
98
|
|
99
|
+
|
78
100
|
# @param [String, Symbol] uid Social network UID
|
101
|
+
# @return [SocialNetsDB::SocialNet, nil]
|
79
102
|
#
|
80
103
|
def find_by_uid(uid)
|
81
104
|
validate_argument_type! uid, String
|
@@ -2,35 +2,15 @@
|
|
2
2
|
|
3
3
|
module Support
|
4
4
|
|
5
|
-
|
5
|
+
extend FnValidations
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# From https://avdi.codes/recursively-symbolize-keys/
|
17
|
-
#
|
18
|
-
def recursively_symbolize_keys(hash)
|
19
|
-
validate_argument_type! hash, Hash
|
20
|
-
hash.inject({}) { |result, (key, value)|
|
21
|
-
new_key = case key
|
22
|
-
when String then key.to_sym
|
23
|
-
else key
|
24
|
-
end
|
25
|
-
|
26
|
-
new_value = case value
|
27
|
-
when Hash then symbolize_keys(value)
|
28
|
-
else value
|
29
|
-
end
|
30
|
-
|
31
|
-
result[new_key] = new_value
|
32
|
-
result
|
33
|
-
}
|
34
|
-
end
|
7
|
+
# Direct analogue of Rails' `String#present?`
|
8
|
+
#
|
9
|
+
# @return [Boolean] is the passed argument is a non-empty String
|
10
|
+
# @param arg [Any] the thing to check
|
11
|
+
#
|
12
|
+
def present_str?(arg)
|
13
|
+
arg.is_a?(String) && arg != ""
|
14
|
+
end
|
35
15
|
|
36
16
|
end
|
@@ -4,33 +4,33 @@ require_relative "support"
|
|
4
4
|
|
5
5
|
module TagHelper
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
7
|
+
include Support
|
8
|
+
|
9
|
+
def tag_attributes_to_s(options)
|
10
|
+
fail ArgumentError, "A Hash must be passed, you pass #{options.class}: #{options.inspect}" unless options.is_a? Hash
|
11
|
+
options.map { |pair| stringify_pair(*pair) }
|
12
|
+
.reject { |stringified_attribute| [nil, ""].include?(stringified_attribute) }
|
13
|
+
.join(" ")
|
14
|
+
end
|
15
|
+
|
16
|
+
private def stringify_pair(attribute_name, attribute_value)
|
17
|
+
str_value = stringify_value(attribute_value)
|
18
|
+
return "" if [nil, ""].include? str_value
|
19
|
+
"#{attribute_name}=\"#{str_value}\""
|
20
|
+
end
|
21
|
+
|
22
|
+
private def stringify_value(value)
|
23
|
+
value.is_a?(Array) ? value.join(" ") : value.to_s
|
24
|
+
end
|
25
|
+
|
26
|
+
def merge_style_values(existing:, incoming:)
|
27
|
+
return existing unless present_str? incoming
|
28
|
+
[existing, "#{incoming};"].join("; ").gsub(";;", ";")
|
29
|
+
end
|
30
|
+
|
31
|
+
def merge_class_values(existing:, incoming:)
|
32
|
+
return existing unless present_str? incoming
|
33
|
+
[existing, incoming]
|
34
|
+
end
|
35
35
|
|
36
36
|
end
|
data/lib/social_nets_db.rb
CHANGED
@@ -10,8 +10,6 @@ require_relative "social_nets_db/social_net"
|
|
10
10
|
|
11
11
|
class SocialNetsDB
|
12
12
|
|
13
|
-
|
14
|
-
# RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).map { _1.transform_keys(&:to_sym) }.freeze
|
15
|
-
RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).freeze
|
13
|
+
RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).freeze
|
16
14
|
|
17
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_nets_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
- !ruby/object:Gem::Version
|
171
171
|
version: '0'
|
172
172
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
173
|
+
rubygems_version: 3.3.4
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: A non-comprehensive database of social nets packed in a Ruby gem
|