social_nets_db 0.0.6 → 0.0.7

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
  SHA256:
3
- metadata.gz: b16ceb6656a59c747798848c9a99d8fd53c5db5fa903b1d2df388534a122cdc3
4
- data.tar.gz: 4f2f515a1e9bf204a33cd01d274df52953db1d24e2a951cf70cbe7c7c4ad50a6
3
+ metadata.gz: 16056e32bc256d743a1b7fa14d16d714d242ee3a3d4ee106d71d51e6bed03c58
4
+ data.tar.gz: e91524ea8abd15b0f24584645605398ffb6026039fa082a240d04e719850f7df
5
5
  SHA512:
6
- metadata.gz: 3441ffff109b6b15a45a85be1100b235422f3dbd3ded19e099a7b3e18811a94226d06393e239052edbb7023b716b1c06c26063dc66ce4e5701f6f048e5f5cea1
7
- data.tar.gz: 76791b05f97311c578435150d61c1780c3980ead21ac60c2cc938a22135bbeef36778f18120759ff2e51283568c783b1fe1897e3b1928a045460ef65dda161a7
6
+ metadata.gz: 72bdf3a625923ec900dcc76d98dd2e01932848b003b51dfcc3fc0589484086a5a2bafb6f71c9a9120e33b410c180dc53837a681b79030879a01016d3d6bb3285
7
+ data.tar.gz: a2fa51dad61a848b70cc82e923ab19b4c41b435487cff99f5620e4ff3c25e0f41d845513bfaffcd0df60ba60c7d7cd0246c36fc9979455846d620ce9fc4786a9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.7] - 2021-12-03
4
+
5
+ - Improves and corrects user page method
6
+ - Corrects .all method
7
+ - More documentation
8
+
3
9
  ## [0.0.6] - 2021-12-03
4
10
 
5
11
  - Corrects data source of accessor methods
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- social_nets_db (0.0.5)
4
+ social_nets_db (0.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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]
@@ -24,28 +27,39 @@ class SocialNetsDB
24
27
  end
25
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
- return unless template = page["by_username"] || page["by_account_id"]
38
- uid = [username, account_id].select { present_str? _1 }.first or fail(ArgumentError, "Either a username or an account id must be provided")
39
-
40
- if username && page["by_username"]
41
- fail ArgumentError, "Either a username or an account id must be provided" unless present_str?(username)
42
- template.sub("${domain}", domain.to_s).sub("${uid}", username)
43
- elsif account_id && page["by_account_id"]
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)
46
- end
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)
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
@@ -13,24 +13,4 @@ module Support
13
13
  arg.is_a?(String) && arg != ""
14
14
  end
15
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
35
-
36
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SocialNetsDB
4
- VERSION = "0.0.6".freeze
4
+ VERSION = "0.0.7".freeze
5
5
  end
@@ -10,8 +10,6 @@ require_relative "social_nets_db/social_net"
10
10
 
11
11
  class SocialNetsDB
12
12
 
13
- # RECORDS = recursively_symbolize_keys(YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__))).freeze
14
- # RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).map { _1.transform_keys(&:to_sym) }.freeze
15
13
  RECORDS = YAML.load_file(File.expand_path("social_nets_db/db.yml", __dir__)).freeze
16
14
 
17
15
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_nets_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Pedan