rest_uri 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cb72238c752bdafc3a8e986139d4e68fc1ea326e
4
+ data.tar.gz: 0781cbbdac948bf2a65c96827bb025780b5106f7
5
+ SHA512:
6
+ metadata.gz: 5b845d9adbc9117bab76f65c094a8d385253073db5a1258497ef099274236a3428a936a98a345bddfa19be284dfdec444f1f9b57611d5fd95bc33f18089a88b1
7
+ data.tar.gz: 5464c41caf644a3ffa7d19ccdc47a78f8e9ae64442168b3c2a61778fb329cced37f5c7d74d17ea2051c0fefe357f0ba696940d3a550cd3fd9e2f6db527564192
data/.editorconfig ADDED
@@ -0,0 +1,10 @@
1
+ root = true
2
+
3
+ [*]
4
+ charset = utf-8
5
+ end_of_line = lf
6
+ indent_style = space
7
+ indent_size = 2
8
+ insert_final_newline = true
9
+ trim_trailing_whitespace = true
10
+ max_line_length = 120
@@ -0,0 +1,10 @@
1
+ | Q | A
2
+ | ------------- | ---
3
+ | Bug fix? | yes/no
4
+ | New feature? | yes/no
5
+ | BC breaks? | yes/no
6
+ | Deprecations? | yes/no
7
+ | Tests pass? | yes/no
8
+ | Fixed tickets | comma-separated list of tickets fixed by the PR, if any
9
+ | License | MIT
10
+ | Doc PR | reference to the documentation PR, if any
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ - 2.1
5
+ - 2.0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,8 @@
1
+ Contributing
2
+ ===
3
+
4
+ 1. Fork it ( https://github.com/announce/tweet_url/fork )
5
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
6
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
7
+ 4. Push to the branch (`git push origin my-new-feature`)
8
+ 5. Create a new Pull Request
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rest_uri (0.0.1)
5
+ activesupport (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (5.0.0.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (~> 0.7)
13
+ minitest (~> 5.1)
14
+ tzinfo (~> 1.1)
15
+ addressable (2.4.0)
16
+ concurrent-ruby (1.0.2)
17
+ diff-lcs (1.2.5)
18
+ i18n (0.7.0)
19
+ minitest (5.9.0)
20
+ rake (10.5.0)
21
+ rspec (3.5.0)
22
+ rspec-core (~> 3.5.0)
23
+ rspec-expectations (~> 3.5.0)
24
+ rspec-mocks (~> 3.5.0)
25
+ rspec-core (3.5.2)
26
+ rspec-support (~> 3.5.0)
27
+ rspec-expectations (3.5.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.5.0)
30
+ rspec-mocks (3.5.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.5.0)
33
+ rspec-support (3.5.0)
34
+ thread_safe (0.3.5)
35
+ tzinfo (1.2.2)
36
+ thread_safe (~> 0.1)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ addressable
43
+ bundler (~> 1.7)
44
+ rake (~> 10.0)
45
+ rest_uri!
46
+ rspec
47
+
48
+ BUNDLED WITH
49
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Kenta Yamamoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ RestUri
2
+ ===
3
+
4
+ [![Build Status](https://travis-ci.org/announce/rest_uri.svg?branch=master)](https://travis-ci.org/announce/rest_uri)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'rest_uri'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install rest_uri
21
+
22
+ ## Usage
23
+
24
+ Simply,
25
+
26
+ ```rb
27
+ tweet_url = RestUri.parse('https://twitter.com/jack/status/761304654147784704/photo/1')
28
+ tweet_url.status_id #=> 761304654147784704
29
+ tweet_url.photo_id #=> 1
30
+ ```
31
+
32
+ To handle URL containing multibyte chars, run `gem install addressable` and
33
+
34
+ ```rb
35
+ require 'addressable/uri'
36
+ require 'rest_uri'
37
+
38
+ rest_uri = RestUri.parse(
39
+ 'https://twitter.com/yukihiro_matz/status/755950562227605504#尾骶骨',
40
+ parser: Addressable::URI)
41
+ rest_uri.status_id #=> 755950562227605504
42
+ ```
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/lib/rest_uri.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'uri'
2
+ require 'rest_uri/version'
3
+ require 'rest_uri/resource'
4
+
5
+ module RestUri
6
+ DEFAULT_PARSER = URI
7
+
8
+ # Retrieve resource ID from REST URI
9
+ # @example
10
+ # require 'addressable/uri'
11
+ # require 'rest_uri'
12
+ # rest_uri = RestUri.parse(
13
+ # 'https://twitter.com/yukihiro_matz/status/755950562227605504#尾骶骨',
14
+ # parser: Addressable::URI)
15
+ # rest_uri.status_id #=> 755950562227605504
16
+ class Base
17
+ include Resource
18
+ attr_accessor :uri, :parser
19
+ def initialize(uri, opts = {})
20
+ @uri = uri
21
+ @parser = opts.has_key?(:parser) ? opts[:parser] : DEFAULT_PARSER
22
+ end
23
+ end
24
+
25
+ # @param uri [String, URI]
26
+ # @param
27
+ # @option opts [Object] :parser URI parser such as Addressable::URI
28
+ def self.parse(uri, opts = {})
29
+ Base.new(uri, opts)
30
+ end
31
+
32
+ end
@@ -0,0 +1,39 @@
1
+ require 'active_support/inflector'
2
+ require 'rest_uri/uri'
3
+
4
+ module RestUri
5
+ module Resource
6
+
7
+ # Take a URI string or URI object and return its ID
8
+ # @example
9
+ # resource_id = RestUri::Resource::resource_id('https://twitter.com/sferik/resource/540897316908331009/')
10
+ # resource_id #=> 540897316908331009
11
+ # @param name [String] Resource name
12
+ # @param object [Integer, String, URI] An ID, URI, or object.
13
+ # @return [Integer, NilClass]
14
+ def self.resource_id(name, object, parser = DEFAULT_PARSER)
15
+ case object
16
+ when ::Integer
17
+ object
18
+ when ::String
19
+ Resource.resource_id(name, parser.parse(object), parser)
20
+ when parser
21
+ Resource.resource_id(name, Uri.hashbang_path_or_path(object).split('/'))
22
+ when Enumerable
23
+ Uri.find_resource_id(object) {|s| /\A(?:#{name.singularize}|#{name.pluralize})\z/ === s}
24
+ else
25
+ nil
26
+ end
27
+ end
28
+
29
+ def resource_id(name)
30
+ Resource.resource_id(name.underscore, @uri, @parser)
31
+ end
32
+
33
+ def method_missing(name, *args)
34
+ super unless name.to_s.end_with? :_id.to_s
35
+ resource_id(name[0...-:_id.to_s.size])
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ module RestUri
2
+ module Uri
3
+
4
+ # Retrieves REST resource ID
5
+ # @param list [String[]]
6
+ # @param &block [Proc]
7
+ # @return [Integer, NilClass]
8
+ def self.find_resource_id(list, &block)
9
+ index = list.index(&block)
10
+ return index if index.nil?
11
+ target = list[index + 1]
12
+ target.nil? ? target : target.to_i
13
+ end
14
+
15
+ # To support old style URL like http://twitter.com/#!/status/759813164686938117
16
+ # @param object [URI]
17
+ # @return [String]
18
+ def self.hashbang_path_or_path(object)
19
+ (not object.fragment.nil? and object.fragment.chars.first == '!') ?
20
+ object.fragment :
21
+ object.path
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module RestUri
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/rest_uri.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rest_uri/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'rest_uri'
8
+ spec.version = RestUri::VERSION
9
+ spec.authors = ['Kenta Yamamoto']
10
+ spec.email = ['ymkjp@jaist.ac.jp']
11
+ spec.summary = 'REST URI parser'
12
+ spec.description = 'Retrieve resource ID from REST URI'
13
+ spec.homepage = 'https://github.com/announce/rest_uri'
14
+ spec.license = 'MIT'
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+ spec.add_dependency 'activesupport', '~> 5.0'
20
+ spec.add_development_dependency 'bundler', '~> 1.7'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'addressable'
24
+ end
data/spec/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestUri::Resource do
4
+ describe '.resource_id' do
5
+ let (:resource) { RestUri::Resource }
6
+ let (:status_id) { 540897316908331009 }
7
+ describe 'takes string URL and extract ID' do
8
+ subject { resource.resource_id('status', "https://twitter.com/sferik/status/#{status_id}/") }
9
+ it { is_expected.to equal status_id }
10
+ end
11
+
12
+ describe 'takes URL object and extract ID' do
13
+ subject { resource.resource_id('status', URI.parse("https://twitter.com/sferik/status/#{status_id}/")) }
14
+ it { is_expected.to equal status_id }
15
+ end
16
+
17
+ describe 'takes URL string and plural name' do
18
+ subject { resource.resource_id('statuses', "https://twitter.com/sferik/status/#{status_id}/") }
19
+ it { is_expected.to equal status_id }
20
+ end
21
+
22
+ describe 'takes URL object and extract ID' do
23
+ subject { resource.resource_id('statuses', "https://twitter.com/sferik/status/#{status_id}/") }
24
+ it { is_expected.to equal status_id }
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe RestUri do
4
+
5
+ it 'has a version number' do
6
+ expect(RestUri::VERSION).not_to be nil
7
+ end
8
+
9
+ let!(:username) { 'i05' }
10
+ let!(:status_id) { 658113992410292224 }
11
+
12
+ describe RestUri::Base do
13
+ context 'Singular resource' do
14
+ let(:tweet_url) { RestUri.parse("https://twitter.com/#{username}/status/#{status_id}") }
15
+ it { expect(tweet_url).to be_instance_of(RestUri::Base)}
16
+ it { expect(tweet_url.status_id).to eq status_id }
17
+ it { expect(tweet_url.statuses_id).to eq status_id }
18
+ end
19
+
20
+ context 'Plural resource' do
21
+ let(:tweet_url) { RestUri.parse("https://twitter.com/#{username}/status/#{status_id}") }
22
+ it { expect(tweet_url).to be_instance_of(RestUri::Base)}
23
+ it { expect(tweet_url.status_id).to eq status_id }
24
+ it { expect(tweet_url.statuses_id).to eq status_id }
25
+ end
26
+
27
+ end
28
+
29
+ context 'with parser option' do
30
+ let(:tweet_url) {
31
+ require 'addressable/uri'
32
+ RestUri.parse(
33
+ "https://twitter.com/#{username}/status/#{status_id}#マルチバイト",
34
+ parser: Addressable::URI)
35
+ }
36
+
37
+ it { expect(tweet_url).to be_instance_of(RestUri::Base)}
38
+ it { expect(tweet_url.parser).to be Addressable::URI}
39
+ it { expect(tweet_url.status_id).to eq status_id }
40
+ end
41
+
42
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'rest_uri'
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rest_uri
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kenta Yamamoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: addressable
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Retrieve resource ID from REST URI
84
+ email:
85
+ - ymkjp@jaist.ac.jp
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".editorconfig"
91
+ - ".github/PULL_REQUEST_TEMPLATE.md"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CONTRIBUTING.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - lib/rest_uri.rb
103
+ - lib/rest_uri/resource.rb
104
+ - lib/rest_uri/uri.rb
105
+ - lib/rest_uri/version.rb
106
+ - rest_uri.gemspec
107
+ - spec/Gemfile
108
+ - spec/rest_uri/resource_spec.rb
109
+ - spec/rest_uri_spec.rb
110
+ - spec/spec_helper.rb
111
+ homepage: https://github.com/announce/rest_uri
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.6.4
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: REST URI parser
135
+ test_files:
136
+ - spec/Gemfile
137
+ - spec/rest_uri/resource_spec.rb
138
+ - spec/rest_uri_spec.rb
139
+ - spec/spec_helper.rb