web_service_uri 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56f1369955baf01342ff7fe664c6d1c73e48ef07042e77ca22dbd6be0a74fdba
4
- data.tar.gz: f5bb2634279d50760ef4aaa0e5ec612b62e5128847e850c0531aa47e25da6a8d
3
+ metadata.gz: 1b00732f5bca4617724d393d5e5d2f8ebafeeb69d7f3b8f06fe1f7cd6ebe0c6f
4
+ data.tar.gz: 5ecd5a3613a6474a77fe9b1efe9f97c049c6aa3fbaffa0c01da7eef42439630b
5
5
  SHA512:
6
- metadata.gz: 6ff9820768fe8b76303fab28cf23ce0a2b555f70c49bc038009a7c2fa593145f3d68aaaa04873164274a6f1248cb6d4cf461846a75f9bcffec82c9dee6ee5dab
7
- data.tar.gz: b80372af80de375fa269a5c32545c8bfd9ae3c83bc35e1159fb8cbaaba48e8ccdff9b1711a66333bbed37082c5fc78cb5565f93c9364cf99bae3beb6cd695f41
6
+ metadata.gz: 46a4fc5080d48f774bc02147d5bc969691d0fe5c15b2a86c5124f1c299f340008cd652a2cf13ef1ac4652d34095927c71e92900e5f279517489cc2f276720a88
7
+ data.tar.gz: 51be020aad6114f891450f6be442921b34e71c4ff3f6ac0e4104c9443193103fcedb30ef44b850866ad4274ef44dc0ea9256ee20433ec9aff7971f4036e6d557
data/README.md CHANGED
@@ -22,21 +22,33 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- ```
25
+ ```ruby
26
+ # expected URI
26
27
  ws_uri = WebServiceUri::WebServiceUri.new "https://github.com/tanakaworld"
27
28
  ws_uri.github?
28
29
  # => true
29
30
  ws_uri.twitter?
30
31
  # => false
32
+ ws_uri.valid?
33
+ # => true
34
+ ws_uri.account_id
35
+ # => "tanakaworld"
36
+
37
+ # unexpected URI
38
+ invalid_ws_uri = WebServiceUri::WebServiceUri.new "https://example.com/example"
39
+ ws_uri.valid?
40
+ # => false
41
+ ws_uri.account_id
42
+ # => nil
31
43
  ```
32
44
 
33
45
  ## Support services
34
46
 
35
- - GitHub
36
- - Twitter
37
- - Facebook
38
- - LinkedIn
39
- - Instagram
47
+ - [GitHub](https://github.com/)
48
+ - [Twitter](https://twitter.com/)
49
+ - [Facebook](https://www.facebook.com/)
50
+ - [LinkedIn](https://www.linkedin.com/)
51
+ - [Instagram](https://www.instagram.com/)
40
52
 
41
53
  ```
42
54
  WebServiceUri::WebServiceUri.available_services
@@ -5,14 +5,32 @@ require "pathname"
5
5
  module WebServiceUri
6
6
  class WebServiceUri
7
7
  attr_reader :original_uri
8
+ attr_reader :service_name
9
+
10
+ @@services = {
11
+ github: 'github.com',
12
+ twitter: 'twitter.com',
13
+ facebook: 'facebook.com',
14
+ linkedin: 'linkedin.com',
15
+ instagram: 'instagram.com'
16
+ }
17
+
18
+ @@services.each do |name, url|
19
+ define_method "#{name}?" do
20
+ @sns_uri.host.include? url
21
+ end
22
+ end
8
23
 
9
24
  def self.available_services
10
- [:github, :twitter, :facebook, :linkedin, :instagram]
25
+ @@services.keys
11
26
  end
12
27
 
13
28
  def initialize(original_uri)
14
29
  @original_uri = original_uri
15
30
  @sns_uri = URI.parse(original_uri)
31
+ @service_name = nil
32
+
33
+ valid?
16
34
  end
17
35
 
18
36
  def path
@@ -25,24 +43,26 @@ module WebServiceUri
25
43
  end
26
44
  end
27
45
 
28
- def github?
29
- @sns_uri.host.include? 'github.com'
30
- end
31
-
32
- def twitter?
33
- @sns_uri.host.include? 'twitter.com'
46
+ def valid?
47
+ @@services.keys.any? do |name|
48
+ is_match = self.send "#{name}?"
49
+ @service_name = name if is_match
50
+ is_match
51
+ end
34
52
  end
35
53
 
36
- def facebook?
37
- @sns_uri.host.include? 'facebook.com'
38
- end
54
+ def account_id
55
+ return nil if @service_name.nil?
39
56
 
40
- def linkedin?
41
- @sns_uri.host.include? 'linkedin.com'
42
- end
57
+ split = @sns_uri.path
58
+ .chomp("/") # remove "/" at the end
59
+ .split("/")
43
60
 
44
- def instagram?
45
- @sns_uri.host.include? 'instagram.com'
61
+ if @service_name == :linkedin
62
+ split[2]
63
+ else
64
+ split[1]
65
+ end
46
66
  end
47
67
  end
48
68
  end
@@ -1,3 +1,3 @@
1
1
  module WebServiceUri
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_service_uri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tanakaworld
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-10 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler