social_nets_db 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d0f34a54ddd600c3eca0d252f6268ccbf1e1218a759cd6e45480e9ec0a861739
4
+ data.tar.gz: c710e00c6e326708c27e635328bf31716c74dbe21e7b29f4b66dd0d40ff03ee0
5
+ SHA512:
6
+ metadata.gz: 528c882f2b6e55a309493fd44577b3e0fa4629035b9cf9cb582d84f7a1ac9ce58d023e9ba9f481cb958022bcb446d71ab206d78a9fbaf96f5ff5b90fc4a69c1f
7
+ data.tar.gz: bcf8336c308bd6f60b3702380d2c059f360c9ade03fcea818c4e27855172c2ae1f0a45191258ae7084e426745a57d9e1590815379aadc79b57a339206b82a4f5
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in integral-social_net.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ social_nets_db (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ bundler-audit (0.9.0.1)
11
+ bundler (>= 1.2.0, < 3)
12
+ thor (~> 1.0)
13
+ byebug (11.1.3)
14
+ coderay (1.1.3)
15
+ diff-lcs (1.4.4)
16
+ method_source (1.0.0)
17
+ parallel (1.21.0)
18
+ parser (3.0.3.1)
19
+ ast (~> 2.4.1)
20
+ pry (0.14.1)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
23
+ pry-byebug (3.8.0)
24
+ byebug (~> 11.0)
25
+ pry (~> 0.10)
26
+ rainbow (3.0.0)
27
+ rake (13.0.6)
28
+ regexp_parser (2.1.1)
29
+ rexml (3.2.5)
30
+ rspec (3.10.0)
31
+ rspec-core (~> 3.10.0)
32
+ rspec-expectations (~> 3.10.0)
33
+ rspec-mocks (~> 3.10.0)
34
+ rspec-core (3.10.1)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-expectations (3.10.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-mocks (3.10.2)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.10.0)
42
+ rspec-support (3.10.3)
43
+ rubocop (1.23.0)
44
+ parallel (~> 1.10)
45
+ parser (>= 3.0.0.0)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.8, < 3.0)
48
+ rexml
49
+ rubocop-ast (>= 1.12.0, < 2.0)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 3.0)
52
+ rubocop-ast (1.14.0)
53
+ parser (>= 3.0.1.1)
54
+ ruby-progressbar (1.11.0)
55
+ thor (1.1.0)
56
+ unicode-display_width (2.1.0)
57
+
58
+ PLATFORMS
59
+ x86_64-darwin-17
60
+
61
+ DEPENDENCIES
62
+ bundler (>= 2, < 3)
63
+ bundler-audit (>= 0.9, < 1)
64
+ pry (< 1)
65
+ pry-byebug (~> 3)
66
+ rake (~> 13)
67
+ rspec (~> 3)
68
+ rubocop (~> 1)
69
+ social_nets_db!
70
+
71
+ BUNDLED WITH
72
+ 2.2.27
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Sergey Pedan
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,325 @@
1
+ # Social nets DB
2
+
3
+ ## Installation
4
+
5
+ ```ruby
6
+ gem "social_nets_db"
7
+ ```
8
+
9
+
10
+ ## Internals
11
+
12
+ It stores data about social nets in a Ruby hash like so:
13
+
14
+ ```yaml
15
+ -
16
+ name: Behance
17
+ uid: behance
18
+ icons:
19
+ font_awesome: "behance"
20
+ color: "#1769ff"
21
+ url: behance.com
22
+ tags:
23
+ - recruiting
24
+ - art
25
+ - design
26
+ profile_url:
27
+ by_username: https://behance.com/${username}
28
+ by_account_id: "https://behance.com/${account_id}"
29
+ ```
30
+
31
+ [Peek into the source](https://github.com/sergeypedan/social-nets-db/blob/master/lib/social_net_db/db.yml).
32
+
33
+ Everything else is just helpers around this simple DB: finders, accessors & view helpers.
34
+
35
+
36
+ ## Usage
37
+
38
+ There are 2 primary use cases for this gem:
39
+
40
+ ### 1. To help create lists of links to social net accounts
41
+
42
+ Like in the footer of a website:
43
+
44
+ ```ruby
45
+ ruby:
46
+ accounts = [
47
+ { net_uid: "instagram", username: "dhh" },
48
+ { net_uid: "facebook", username: "d-h-h" },
49
+ { net_uid: "twitter", username: "d_h_h" },
50
+ { net_uid: "upwork", account_id: "401298374012374" }
51
+ ]
52
+
53
+ ul
54
+ - accounts.each do |account|
55
+ - net = SocialNetsDB.find account[:net_uid]
56
+ li
57
+ = fa_icon net.icons["font_awesome"], style: "color: #{net.color}"
58
+ =< link_to net.name, \
59
+ net.user_page(username: account[:username], account_id: account[:account_id]), \
60
+ target: "_blank", \
61
+ rel: "noopener noreferrer"
62
+ ```
63
+
64
+ Here the gem:
65
+
66
+ - builds the URL to user page
67
+
68
+ ```ruby
69
+ net.user_page(username: account[:username])
70
+ # "https://facebook.com/dhh"
71
+ ```
72
+
73
+ - gives you the correct name of the social net
74
+
75
+ ```ruby
76
+ net.name
77
+ # "Facebook"
78
+ ```
79
+
80
+ ### 2. To help building a `<select>` with social nets when storing user's account link
81
+
82
+ ```ruby
83
+ = form_for @user do |f|
84
+ = f.fields_for :social_net_accounts do |sna|
85
+ .form-group
86
+ = sna.label :social_net_uid, class: "control-label"
87
+ = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
88
+ ```
89
+
90
+ which produces
91
+
92
+ ```html
93
+ <form action="/users" method="POST">
94
+ <div class="form-group">
95
+ <label for="user_social_net_accounts_attributes_123_social_net_uid">Social net UID</label>
96
+ <select required="required" class="form-control" name="user[social_net_accounts_attributes][123][social_net_uid]">
97
+ <option value="">Choose a social net:</option>
98
+ <option value="behance">Behance</option>
99
+ <option value="dribble">Dribble</option>
100
+ <option value="facebook">Facebook</option>
101
+ <!-- ... -->
102
+ </select>
103
+ </div>
104
+ </form>
105
+ ```
106
+
107
+ See section “[Using with Rails](#use-with-rails)” below for more details.
108
+
109
+
110
+ ## API
111
+
112
+ ### Instance of `SocialNetsDB` class
113
+
114
+ Initialize an instance with social net UID.
115
+
116
+ ```ruby
117
+ social_net = SocialNetsDB.find("facebook")
118
+ # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
119
+ ```
120
+
121
+ Which are supported UIDs?
122
+
123
+ ```ruby
124
+ SocialNetsDB.uids
125
+ #=> [
126
+ # "behance",
127
+ # "dribble",
128
+ # "facebook",
129
+ # "fl.ru",
130
+ # "freelansim",
131
+ # "habr",
132
+ # "github",
133
+ # "instagram",
134
+ # "livejournal",
135
+ # "linkedin",
136
+ # "medium",
137
+ # "my.mail.ru",
138
+ # "odnoklassniki",
139
+ # "stackoverflow",
140
+ # "telegram",
141
+ # "twitter",
142
+ # "upwork",
143
+ # "vkontakte",
144
+ # "youtube"
145
+ # ]
146
+ ```
147
+
148
+ If you try to initialize with an unsupported UID, and you will also get the list along with an Exception:
149
+
150
+ ```ruby
151
+ SocialNetsDB.find("diaspora")
152
+ # ArgumentError (Social net with UID test is not supported.
153
+ #
154
+ # Currently supported UIDs are: behance, dribble, facebook, github, instagram, livejournal, linkedin, medium, my.mail.ru, odnoklassniki, stackoverflow, telegram, twitter, vkontakte, youtube)
155
+ ```
156
+
157
+ ### find_by
158
+
159
+ If you don't want to rescue exceptions while initializing, you can use `find_by(uid:)` instead.
160
+
161
+ It returns an instance:
162
+
163
+ ```ruby
164
+ SocialNetsDB.find_by(uid: "facebook")
165
+ # => #<SocialNetsDB:0x00007fddc0041b40 @uid="facebook">
166
+ ```
167
+
168
+ or `nil`:
169
+
170
+ ```ruby
171
+ SocialNetsDB.find_by(uid: "blabla")
172
+ # => nil
173
+ ```
174
+
175
+ ### Data
176
+
177
+ ```ruby
178
+ social_net.to_h
179
+ # => {
180
+ # name: "Facebook",
181
+ # uid: "facebook",
182
+ # fa_id: "facebook",
183
+ # color: "crimson",
184
+ # url: "https://facebook.com",
185
+ # user_page: {
186
+ # by_username: "https://facebook.com/${username}",
187
+ # by_account_id: "https://facebook.com/${account_id}",
188
+ # methods: [:account_id, :username]
189
+ # }
190
+ # }
191
+ ```
192
+
193
+ ### Property accessors
194
+
195
+ ```ruby
196
+ social_net.color #=> "#3C5A99"
197
+ social_net.fa_icon_id #=> "facebook"
198
+ social_net.name #=> "Facebook"
199
+ social_net.uid #=> "facebook"
200
+ social_net.url #=> "https://facebook.com"
201
+ ```
202
+
203
+ ### FontAwesome icon
204
+
205
+ Assumes you have [FontAwesome](https://fontawesome.com/v4.7.0/) installed. Just builds the HTML tag.
206
+
207
+ ```ruby
208
+ social_net.fa_icon
209
+ #=> <span class="fa fa-facebook" style="color: #3C5A99"></span>
210
+ ```
211
+
212
+ It accepts a Hash with attributes, like Rails `tag_helper` (but not for `data: {}` — maybe later):
213
+
214
+ ```ruby
215
+ social_net.fa_icon(class: "fa-fw", id: "my-id", style: "margin-top: 10px")
216
+ #=> <span class="fa fa-facebook fa-fw" style="color: #3C5A99; margin-top: 10px;" id="my-id"></span>
217
+ ```
218
+
219
+ Exporting social net brand color to `styles` attribute can be turned off by passing `color: false` Hash pair among others:
220
+
221
+ ```ruby
222
+ social_net.fa_icon(color: false, class: "fa-fw", id: "my-id", style: "margin-top: 10px")
223
+ #=> <span class="fa fa-facebook fa-fw" style="cmargin-top: 10px;" id="my-id"></span>
224
+ ```
225
+
226
+ ### User's page URL
227
+
228
+ ```ruby
229
+ social_net.user_page(username: "dhh") #=> "https://facebook.com/dhh"
230
+ social_net.user_page(account_id: "id1234566789") #=> "https://facebook.com/account/id1234566789"
231
+ ```
232
+
233
+ If you pass a username, whild the `SocialNet` supports user page URLs only via account ids, the method call will return `nil`.
234
+
235
+ You can check which is supported
236
+
237
+ ```ruby
238
+ social_net.user_page_methods #=> [:account_id, :username]
239
+ ```
240
+
241
+
242
+ ## Use with Rails
243
+
244
+ This gem is Rails-agnostic, but you can use it in Rails like so:
245
+
246
+ ### Forms
247
+
248
+ ```ruby
249
+ = form_for @user do |f|
250
+ = f.fields_for :social_net_accounts do |sna|
251
+ .form-group
252
+ = sna.label :social_net_uid, class: "control-label"
253
+ = sna.select :social_net_uid, SocialNetsDB.values_for_select, {}, class: "form-control"
254
+ ```
255
+
256
+ because
257
+
258
+ ```ruby
259
+ SocialNetsDB.values_for_select
260
+ #=> [
261
+ # ["Behance", "behance"],
262
+ # ["Dribble", "dribble"],
263
+ # ["Facebook", "facebook"],
264
+ # ["GitHub", "github"],
265
+ # ["Instagram", "instagram"],
266
+ # ["LiveJournal", "livejournal"],
267
+ # ["LinkedIn", "linkedin"],
268
+ # ["Medium", "medium"],
269
+ # ["Мой мир", "my.mail.ru"],
270
+ # ["Одноклассники", "odnoklassniki"],
271
+ # ["StackOverflow", "stackoverflow"],
272
+ # ["Telegram", "telegram"],
273
+ # ["Twitter", "twitter"],
274
+ # ["Вконтакте", "vkontakte"],
275
+ # ["YouTube", "youtube"]
276
+ # ]
277
+ ```
278
+
279
+ ### Models
280
+
281
+ ```ruby
282
+ model User < ApplicationRecord
283
+ has_many :social_net_accounts
284
+ end
285
+ ```
286
+
287
+ ```ruby
288
+ model SocialNetAccount < ApplicationRecord
289
+ belongs_to :user
290
+
291
+ validates :account_id, presence: true, if: Proc.new { |record| record.username.blank? }
292
+ validates :social_net_uid, presence: true, inclusion: { in: SocialNetsDB.uids }
293
+ validates :username, presence: true, if: Proc.new { |record| record.account_id.blank? }
294
+
295
+ def social_net
296
+ @social_net ||= SocialNetsDB.find(self.social_net_uid)
297
+ end
298
+
299
+ def user_page
300
+ social_net.user_page(username: self.username, account_id: self.account_number)
301
+ end
302
+
303
+ # id :bigint not null, primary key
304
+ # user_id :bigint not null
305
+ # account_id :string example: `id1230948712034871`
306
+ # social_net_uid :string not null example: `facebook`, `vkontakte`
307
+ # username :string example, `tenderlove`
308
+ # userpic_url :string
309
+ end
310
+ ```
311
+
312
+ It's probably better to move those 2 methods into a decorator — here they are in the model just for brevity.
313
+
314
+ ```ruby
315
+ SocialNetAccount.create(user_id: User.first.id, social_net_uid: "facebook", username: "tenderlobe")
316
+ ```
317
+
318
+ ```ruby
319
+ @user.social_net_accounts.first.user_page #=> "https://facebook.com/tenderlove"
320
+ ```
321
+
322
+
323
+ ## License
324
+
325
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "bundler/audit/task"
5
+ require "rspec/core/rake_task"
6
+ require "rubocop/rake_task"
7
+
8
+ Bundler::Audit::Task.new
9
+ RSpec::Core::RakeTask.new(:spec)
10
+ RuboCop::RakeTask.new
11
+ rescue LoadError => e
12
+ puts e.message
13
+ end
14
+
15
+ desc "Run code quality checks"
16
+ task code_quality: %i[bundle:audit rubocop]
17
+
18
+ task default: %i[code_quality spec]