forward-slash 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9047ff27e33ef18ea9f4f9dc2528abf6260970cf
4
+ data.tar.gz: fa7c3431bbaded3158c2eb6f36ba855fd5d9a136
5
+ SHA512:
6
+ metadata.gz: dca28114a6cd60f4ec9a3e3462a1bf3a3b740f809b19d54a4a15a4bff15437768c26381ffe54a8f86fafdbe69aad321e672a177f1349a54a8fcccfe8ee761a00
7
+ data.tar.gz: 876297fd2af8c800f7be3822a70f67fe78c9a28f8682bf7b46b08ebc418178e11a4f17d7f825345b736f54dd1fa2527bb198c52e1c0be28dc562267f0130583e
@@ -0,0 +1,3 @@
1
+ .bundle
2
+ spec/examples.txt
3
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.2.4
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,54 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ forward-slash (0.0.1)
5
+ binding_of_caller (~> 0.7.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.4.0)
11
+ binding_of_caller (0.7.2)
12
+ debug_inspector (>= 0.0.1)
13
+ coderay (1.1.1)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ debug_inspector (0.0.2)
17
+ diff-lcs (1.2.5)
18
+ hashdiff (0.3.0)
19
+ method_source (0.8.2)
20
+ pry (0.10.3)
21
+ coderay (~> 1.1.0)
22
+ method_source (~> 0.8.1)
23
+ slop (~> 3.4)
24
+ rspec (3.4.0)
25
+ rspec-core (~> 3.4.0)
26
+ rspec-expectations (~> 3.4.0)
27
+ rspec-mocks (~> 3.4.0)
28
+ rspec-core (3.4.4)
29
+ rspec-support (~> 3.4.0)
30
+ rspec-expectations (3.4.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.4.0)
33
+ rspec-mocks (3.4.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.4.0)
36
+ rspec-support (3.4.1)
37
+ safe_yaml (1.0.4)
38
+ slop (3.6.0)
39
+ webmock (1.22.6)
40
+ addressable (>= 2.3.6)
41
+ crack (>= 0.3.2)
42
+ hashdiff
43
+
44
+ PLATFORMS
45
+ ruby
46
+
47
+ DEPENDENCIES
48
+ forward-slash!
49
+ pry (~> 0.10.1)
50
+ rspec (~> 3.4.0)
51
+ webmock (~> 1.22.6)
52
+
53
+ BUNDLED WITH
54
+ 1.11.2
@@ -0,0 +1,25 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ Copyright © 2016 Chris Sinjakli
5
+
6
+ Permission is hereby granted, free of charge, to any person
7
+ obtaining a copy of this software and associated documentation
8
+ files (the “Software”), to deal in the Software without
9
+ restriction, including without limitation the rights to use,
10
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the
12
+ Software is furnished to do so, subject to the following
13
+ conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # ForwardSlash
2
+
3
+ An HTTP client with REST literals
4
+
5
+ # Description
6
+
7
+ ForwardSlash makes REST a first-class citizen of the Ruby programming language. Rather than forcing developers to write code that makes calls to URLs over HTTP, ForwardSlash lets you drop the URL right in your code - no more worrying about what HTTP is. [This blog post](http://blog.sinjakli.co.uk/2016/04/04/forwardslash-taking-back-the-restful-operator/) explains it best.
8
+
9
+ # Getting started
10
+
11
+ Install the gem:
12
+
13
+ ```
14
+ gem install forward-slash
15
+ ```
16
+
17
+ Then include the `ForwardSlash` module in a class you want to make HTTP calls from, and you're good to go! Here's a runnable example (taken from the `examples` folder):
18
+
19
+ ```ruby
20
+ #!/usr/bin/env ruby
21
+
22
+ $LOAD_PATH.unshift 'lib'
23
+ require "bundler"
24
+ Bundler.require
25
+
26
+ class CurrentIp
27
+ include ForwardSlash
28
+
29
+ def self.print
30
+ http://ifconfig.me/ip
31
+ puts result
32
+ end
33
+ end
34
+
35
+ CurrentIp.print
36
+ ```
37
+
38
+ # Limitations
39
+
40
+ Anything that isn't valid Ruby syntax is unsupported, including:
41
+
42
+ - Query strings
43
+ - Trailing slashes on URLs
44
+
45
+ # Should I use this?
46
+
47
+ \#yeauxleaux
48
+
49
+ ![I regret nothing](https://i.imgur.com/27UuUwL.gif)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift 'lib'
4
+ require "bundler"
5
+ Bundler.require
6
+
7
+ class CurrentIp
8
+ include ForwardSlash
9
+
10
+ def self.print
11
+ http://ifconfig.me/ip
12
+ puts result
13
+ end
14
+ end
15
+
16
+ CurrentIp.print
@@ -0,0 +1,30 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "forward_slash/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "forward-slash"
7
+ s.version = ForwardSlash::VERSION
8
+ s.date = "2016-04-04"
9
+ s.summary = "An HTTP client with REST literals"
10
+ s.description = <<-EOF
11
+ ForwardSlash makes REST a first-class citizen of the Ruby programming language.
12
+ Rather than forcing developers to write code that makes calls to URLs over HTTP,
13
+ ForwardSlash lets you drop the URL right in your code - no more worrying about
14
+ what HTTP is.
15
+
16
+ This blog post explains it best: http://blog.sinjakli.co.uk/2016/04/04/forwardslash-taking-back-the-restful-operator/
17
+ EOF
18
+ s.authors = ["Chris Sinjakli"]
19
+ s.email = "chris@sinjakli.co.uk"
20
+ s.files = `git ls-files`.split("\n")
21
+ s.require_paths = ["lib"]
22
+ s.homepage = "https://github.com/sinjo/forward-slash"
23
+ s.license = "MIT"
24
+
25
+ s.add_dependency "binding_of_caller", "~> 0.7.2"
26
+
27
+ s.add_development_dependency "pry", "~> 0.10.1"
28
+ s.add_development_dependency "rspec", "~> 3.4.0"
29
+ s.add_development_dependency "webmock", "~> 1.22.6"
30
+ end
@@ -0,0 +1,30 @@
1
+ require "binding_of_caller"
2
+ require "forward_slash/core_ext/symbol"
3
+ require "forward_slash/domain_part"
4
+
5
+ module ForwardSlash
6
+ def self.included(base)
7
+ base.send(:attr_reader, :result)
8
+ base.define_singleton_method(:result) do
9
+ @result
10
+ end
11
+
12
+ base.extend self
13
+ end
14
+
15
+ def http(url)
16
+ result = Net::HTTP.get(URI("http://#{url.part}"))
17
+ calling_object = binding.of_caller(1).receiver
18
+ calling_object.instance_variable_set(:@result, result)
19
+ end
20
+
21
+ def https(url)
22
+ result = Net::HTTP.get(URI("https://#{url.part}"))
23
+ calling_object = binding.of_caller(1).receiver
24
+ calling_object.instance_variable_set(:@result, result)
25
+ end
26
+
27
+ def method_missing(part, *args)
28
+ DomainPart.new(part.to_s)
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ class Symbol
2
+ def /(other)
3
+ other
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require "net/http"
2
+
3
+ module ForwardSlash
4
+ class DomainPart
5
+ attr_reader :part
6
+
7
+ def initialize(part)
8
+ @part = part
9
+ end
10
+
11
+ def -(other)
12
+ @part += "-#{other.part}"
13
+ self
14
+ end
15
+
16
+ def /(other)
17
+ @part += "/#{other.part}"
18
+ self
19
+ end
20
+
21
+ def method_missing(next_domain_part, *args)
22
+ @part += ".#{next_domain_part.to_s}"
23
+ self
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module ForwardSlash
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,73 @@
1
+ require "forward_slash"
2
+
3
+ RSpec.describe ForwardSlash do
4
+ let(:fetcher) {
5
+ Class.new do
6
+ include ForwardSlash
7
+
8
+ def initialize(url)
9
+ @url = url
10
+ end
11
+
12
+ def test_fetch
13
+ eval @url
14
+ result
15
+ end
16
+
17
+ def self.test_fetch(url)
18
+ eval url
19
+ result
20
+ end
21
+ end
22
+ }
23
+
24
+ shared_examples_for "performing HTTP requests" do
25
+ context "in instance methods" do
26
+ it "fetches the page and saves the result" do
27
+ expect(fetcher.new(url).test_fetch).to eq(response)
28
+ end
29
+ end
30
+
31
+ context "in class methods" do
32
+ it "fetches the page and saves the result" do
33
+ expect(fetcher.test_fetch(url)).to eq(response)
34
+ end
35
+ end
36
+ end
37
+
38
+ shared_examples_for "different URL structures" do
39
+ let(:url) { "#{scheme}://example.com" }
40
+
41
+ include_examples "performing HTTP requests"
42
+
43
+ context "with a hyphen" do
44
+ let(:url) { "#{scheme}://exa-mple.com" }
45
+
46
+ include_examples "performing HTTP requests"
47
+ end
48
+
49
+ context "with a path after the domain" do
50
+ let(:url) { "#{scheme}://example.com/foo" }
51
+
52
+ include_examples "performing HTTP requests"
53
+ end
54
+ end
55
+
56
+ let(:response) { "Hello" }
57
+
58
+ before do
59
+ stub_request(:get, url).to_return(body: response)
60
+ end
61
+
62
+ context "for plain HTTP" do
63
+ let(:scheme) { "http" }
64
+
65
+ include_examples "different URL structures"
66
+ end
67
+
68
+ context "for HTTPS" do
69
+ let(:scheme) { "https" }
70
+
71
+ include_examples "different URL structures"
72
+ end
73
+ end
@@ -0,0 +1,100 @@
1
+ require "webmock/rspec"
2
+
3
+ WebMock.disable_net_connect!
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
8
+ # this file to always be loaded, without a need to explicitly require it in any
9
+ # files.
10
+ #
11
+ # Given that it is always loaded, you are encouraged to keep this file as
12
+ # light-weight as possible. Requiring heavyweight dependencies from this file
13
+ # will add to the boot time of your test suite on EVERY test run, even for an
14
+ # individual file that may not need all of that loaded. Instead, consider making
15
+ # a separate helper file that requires the additional dependencies and performs
16
+ # the additional setup, and require it from the spec files that actually need
17
+ # it.
18
+ #
19
+ # The `.rspec` file also contains a few flags that are not defaults but that
20
+ # users commonly want.
21
+ #
22
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
23
+ RSpec.configure do |config|
24
+ # rspec-expectations config goes here. You can use an alternate
25
+ # assertion/expectation library such as wrong or the stdlib/minitest
26
+ # assertions if you prefer.
27
+ config.expect_with :rspec do |expectations|
28
+ # This option will default to `true` in RSpec 4. It makes the `description`
29
+ # and `failure_message` of custom matchers include text for helper methods
30
+ # defined using `chain`, e.g.:
31
+ # be_bigger_than(2).and_smaller_than(4).description
32
+ # # => "be bigger than 2 and smaller than 4"
33
+ # ...rather than:
34
+ # # => "be bigger than 2"
35
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
36
+ end
37
+
38
+ # rspec-mocks config goes here. You can use an alternate test double
39
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
40
+ config.mock_with :rspec do |mocks|
41
+ # Prevents you from mocking or stubbing a method that does not exist on
42
+ # a real object. This is generally recommended, and will default to
43
+ # `true` in RSpec 4.
44
+ mocks.verify_partial_doubles = true
45
+ end
46
+
47
+ # Limits the available syntax to the non-monkey patched syntax that is
48
+ # recommended. For more details, see:
49
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
50
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
51
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
52
+ config.disable_monkey_patching!
53
+
54
+ # This setting enables warnings. It's recommended, but in some cases may
55
+ # be too noisy due to issues in dependencies.
56
+ config.warnings = true
57
+
58
+ # Run specs in random order to surface order dependencies. If you find an
59
+ # order dependency and want to debug it, you can fix the order by providing
60
+ # the seed, which is printed after each run.
61
+ # --seed 1234
62
+ config.order = :random
63
+
64
+ # Seed global randomization in this process using the `--seed` CLI option.
65
+ # Setting this allows you to use `--seed` to deterministically reproduce
66
+ # test failures related to randomization by passing the same `--seed` value
67
+ # as the one that triggered the failure.
68
+ Kernel.srand config.seed
69
+
70
+ # Allows RSpec to persist some state between runs in order to support
71
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
72
+ # you configure your source control system to ignore this file.
73
+ config.example_status_persistence_file_path = "spec/examples.txt"
74
+
75
+ # The settings below are suggested to provide a good initial experience
76
+ # with RSpec, but feel free to customize to your heart's content.
77
+ =begin
78
+ # These two settings work together to allow you to limit a spec run
79
+ # to individual examples or groups you care about by tagging them with
80
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
81
+ # get run.
82
+ config.filter_run :focus
83
+ config.run_all_when_everything_filtered = true
84
+
85
+ # Many RSpec users commonly either run the entire suite or an individual
86
+ # file, and it's useful to allow more verbose output when running an
87
+ # individual spec file.
88
+ if config.files_to_run.one?
89
+ # Use the documentation formatter for detailed output,
90
+ # unless a formatter has already been configured
91
+ # (e.g. via a command-line flag).
92
+ config.default_formatter = 'doc'
93
+ end
94
+
95
+ # Print the 10 slowest examples and example groups at the
96
+ # end of the spec run, to help surface which specs are running
97
+ # particularly slow.
98
+ config.profile_examples = 10
99
+ =end
100
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forward-slash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Sinjakli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: binding_of_caller
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.7.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.7.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.4.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.22.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.22.6
69
+ description: |
70
+ ForwardSlash makes REST a first-class citizen of the Ruby programming language.
71
+ Rather than forcing developers to write code that makes calls to URLs over HTTP,
72
+ ForwardSlash lets you drop the URL right in your code - no more worrying about
73
+ what HTTP is.
74
+
75
+ This blog post explains it best: http://blog.sinjakli.co.uk/2016/04/04/forwardslash-taking-back-the-restful-operator/
76
+ email: chris@sinjakli.co.uk
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - ".rspec"
83
+ - ".ruby-version"
84
+ - Gemfile
85
+ - Gemfile.lock
86
+ - LICENSE.md
87
+ - README.md
88
+ - examples/print_current_ip
89
+ - forward-slash.gemspec
90
+ - lib/forward_slash.rb
91
+ - lib/forward_slash/core_ext/symbol.rb
92
+ - lib/forward_slash/domain_part.rb
93
+ - lib/forward_slash/version.rb
94
+ - spec/forward_slash_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/sinjo/forward-slash
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.4.5.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: An HTTP client with REST literals
120
+ test_files: []