gradesfirst 0.3.0 → 0.3.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzdkMjkxNTYwZmZmMjljMjQzZTA0NWI3NGNmNDRjNmE1NDY0YmY3Zg==
5
+ data.tar.gz: !binary |-
6
+ MmFiNTQxMjRlZWY4ZjM5NmJmNjFmMjc5ODc4NGZiYzBmYzFiZjM3NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTJjOTE0YmM5MjNmZDVhNjlmZmJjMjk3MGQ0NzhjNmZmMDJjNjQyNTNhYWMw
10
+ YzBmOTllYTdhMzdhYzg5NDQzODllNGNlYjc3YWVjNzk4OGRlOWE0NDZlZDll
11
+ N2MwMjIzMGIxMTI2ODMwMDAzMjZlN2I5MzhkOThkYzBmOWFjNjM=
12
+ data.tar.gz: !binary |-
13
+ OWY0OWE5NTk5NDc5NjcyN2Q5YjQzYTQyMmI3Zjc2YWY5NWZlYjk1ZmJlZjI2
14
+ YzViZjc3YTE4ZWNkYmYyYTgyMjM2NTBkY2Y5NTNkOWNmZDg4OGQxMTYxNjYw
15
+ MTFiMTA4YjE1M2RhNDQ3ZjczYWEyZWU0NjZiNmNkZTY0MThiYTY=
data/Gemfile CHANGED
@@ -6,3 +6,4 @@ gem 'thor', '~> 0.18.1'
6
6
  gem 'webmock', '~> 1.16.0'
7
7
  gem 'pry'
8
8
  gem 'pry-debugger'
9
+ gem 'http_magic', '~> 0.1'
data/Gemfile.lock CHANGED
@@ -12,6 +12,7 @@ GEM
12
12
  debugger-ruby_core_source (~> 1.2.4)
13
13
  debugger-linecache (1.2.0)
14
14
  debugger-ruby_core_source (1.2.4)
15
+ http_magic (0.1.1)
15
16
  method_source (0.8.2)
16
17
  minitest (4.7.5)
17
18
  pry (0.9.12.4)
@@ -33,6 +34,7 @@ PLATFORMS
33
34
  ruby
34
35
 
35
36
  DEPENDENCIES
37
+ http_magic (~> 0.1)
36
38
  minitest (~> 4.7.0)
37
39
  pry
38
40
  pry-debugger
data/gradesfirst.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.platform = Gem::Platform::RUBY
3
3
  s.name = "gradesfirst"
4
- s.version = "0.3.0"
4
+ s.version = "0.3.2"
5
5
  s.summary = "GradesFirst command line utility for developers."
6
6
  s.description = "This utility will help manage the various tasks developers need to do on their workstation such as database updates."
7
7
  s.license = "MIT"
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
23
23
  s.require_paths = ['lib']
24
24
 
25
25
  s.add_dependency('thor', '~> 0.18.1')
26
+ s.add_dependency('http_magic', '~> 0.1.2')
26
27
  s.add_development_dependency('minitest', '~> 4.7.0')
27
28
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gradesfirst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
5
- prerelease:
4
+ version: 0.3.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - GradesFirst
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-20 00:00:00.000000000 Z
11
+ date: 2014-03-10 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: thor
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,15 +20,27 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.18.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: http_magic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.2
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: minitest
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
45
  - - ~>
36
46
  - !ruby/object:Gem::Version
@@ -38,7 +48,6 @@ dependencies:
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
52
  - - ~>
44
53
  - !ruby/object:Gem::Version
@@ -72,10 +81,6 @@ files:
72
81
  - lib/gradesfirst/task_list_command.rb
73
82
  - lib/gradesfirst/task_move_command.rb
74
83
  - lib/gradesfirst/task_toggle_command.rb
75
- - lib/http_magic.rb
76
- - lib/http_magic/api.rb
77
- - lib/http_magic/request.rb
78
- - lib/http_magic/uri.rb
79
84
  - lib/pivotal_tracker.rb
80
85
  - test/branch_command_test.rb
81
86
  - test/cli_test.rb
@@ -94,10 +99,6 @@ files:
94
99
  - test/fixtures/task_toggled.txt
95
100
  - test/fixtures/tasks.json
96
101
  - test/fixtures/tasks.txt
97
- - test/http_magic/api/get_test.rb
98
- - test/http_magic/api/post_test.rb
99
- - test/http_magic/request_test.rb
100
- - test/http_magic/uri_test.rb
101
102
  - test/support/pivotal_test_helper.rb
102
103
  - test/support/request_expectation.rb
103
104
  - test/task_add_command_test.rb
@@ -109,26 +110,25 @@ files:
109
110
  homepage: http://www.gradesfirst.com
110
111
  licenses:
111
112
  - MIT
113
+ metadata: {}
112
114
  post_install_message:
113
115
  rdoc_options: []
114
116
  require_paths:
115
117
  - lib
116
118
  required_ruby_version: !ruby/object:Gem::Requirement
117
- none: false
118
119
  requirements:
119
120
  - - ! '>='
120
121
  - !ruby/object:Gem::Version
121
122
  version: 1.8.7
122
123
  required_rubygems_version: !ruby/object:Gem::Requirement
123
- none: false
124
124
  requirements:
125
125
  - - ! '>='
126
126
  - !ruby/object:Gem::Version
127
127
  version: 1.3.6
128
128
  requirements: []
129
129
  rubyforge_project:
130
- rubygems_version: 1.8.24
130
+ rubygems_version: 2.2.2
131
131
  signing_key:
132
- specification_version: 3
132
+ specification_version: 4
133
133
  summary: GradesFirst command line utility for developers.
134
134
  test_files: []
data/lib/http_magic.rb DELETED
@@ -1,4 +0,0 @@
1
- require 'http_magic/api'
2
-
3
- module HttpMagic
4
- end
@@ -1,233 +0,0 @@
1
- require 'json'
2
- require 'http_magic/uri'
3
- require 'http_magic/request'
4
-
5
- module HttpMagic
6
- # A magical class that interacts with HTTP resources with a minimal amount of
7
- # configuration.
8
- #
9
- # Assuming an api where the url http://www.example.com/api/v1/foo/99 responds
10
- # with the following.
11
- #
12
- # Header:
13
- #
14
- # Content-Type: application/json
15
- #
16
- # Body:
17
- #
18
- # {
19
- # "name": "Foo Bar"
20
- # }
21
- #
22
- # == Example
23
- #
24
- # class ExampleApi < HttpMagic::Api
25
- # url 'www.example.com'
26
- # namespace 'api/v1'
27
- # headers({'X-AuthToken' => 'token'})
28
- # end
29
- #
30
- # ExampleApi.foo[99].get['name']
31
- # => "Foo Bar"
32
- #
33
- # ExampleApi.foo.create.post(name: 'New Foo')
34
- # => { 'name' => 'New Foo' }
35
- class Api < BasicObject
36
- # Makes the new method private so that instances of this class and it's
37
- # children can only be instantiated through the class method method_missing.
38
- # This is needed to enforce the intended usage of HttpMagic where the class
39
- # is configured to represent an http location. Once it is configured, the
40
- # location is interacted with dynamically with chained methods that correspond
41
- # with parts of URNs found at the location.
42
- class << self
43
- private :new
44
- end
45
-
46
- # Sets or returns the request headers for an HttpMagic based class. The
47
- # headers will be passed along to each resource request being made.
48
- #
49
- # == Example
50
- #
51
- # class ExampleApi < HttpMagic:Api
52
- # url 'www.example.com'
53
- # headers({'X-AuthToken' => 'token'})
54
- # end
55
- def self.headers(value = :not_provided)
56
- unless value == :not_provided
57
- @headers = value
58
- end
59
- @headers
60
- end
61
-
62
- # Sets or returns the namespace for an HttpMagic based class. The namespace
63
- # will be prefixed to the urn for each request made to the url.
64
- #
65
- # Assuming an api where each resource is namespaced with 'api/v1' and where
66
- # the url http://www.example.com/api/v1/foo/99 responds with the following.
67
- #
68
- # Header:
69
- #
70
- # Content-Type: application/json
71
- #
72
- # Body:
73
- #
74
- # {
75
- # "name": "Foo Bar"
76
- # }
77
- #
78
- # == Example
79
- #
80
- # class ExampleApi < HttpMagic:Api
81
- # url 'www.example.com'
82
- # namespace 'api/v1'
83
- # end
84
- #
85
- # ExampleApi.foo[99].get['name']
86
- # => "Foo Bar"
87
- #
88
- def self.namespace(value = :not_provided)
89
- unless value == :not_provided
90
- @namespace = value
91
- end
92
- @namespace
93
- end
94
-
95
- # Sets or returns the uniform resource locator for the HTTP resource.
96
- #
97
- # == Example
98
- #
99
- # class ExampleApi < HttpMagic::Api
100
- # url 'www.example.com'
101
- # end
102
- def self.url(value = :not_provided)
103
- unless value == :not_provided
104
- @url = value
105
- end
106
- @url
107
- end
108
-
109
- # Class scoped method_missing that starts the magic of creating urns
110
- # through meta programming by instantiating an instance of the class
111
- # and delegating the first part of the urn to that instance. This method
112
- # is an implementation of the Factory Method design pattern.
113
- def self.method_missing(name, *args, &block)
114
- new(@url, @namespace, @headers).__send__(name, *args)
115
- end
116
-
117
- def initialize(url, namespace, headers)
118
- @uri = Uri.new(url)
119
- @uri.namespace = namespace
120
- @headers = headers
121
- end
122
-
123
- # Resource index reference intended to allow for the use of numbers in a urn
124
- # such as the following 'foo/99' being referenced by ExampleApi.foo[99]. It
125
- # can also be used to allow for HttpMagic methods to be specified for a urn
126
- # such as 'foo/get' being referenced by ExampleApi.foo[:get]. Finally, it can
127
- # be used for urn parts that are not valid Ruby methods such as 'foo/%5B%5D'
128
- # being referenced by ExampleApi.foo["%5B%5D"].
129
- #
130
- # * part - a part of a urn such that 'foo' and 'bar' would be parts of the urn
131
- # 'foo/bar'.
132
- #
133
- # Returns a reference to its instance so that urn parts can be chained
134
- # together.
135
- def [](part)
136
- @uri.parts << part.to_s
137
- self
138
- end
139
-
140
- def delete
141
- request = Request.new(@uri,
142
- headers: @headers
143
- )
144
- request.delete
145
- end
146
-
147
- # Gets a resource from the URI and returns it based on its content type.
148
- # JSON content will be parsed and returned as equivalent Ruby objects. All
149
- # other content types will be returned as text.
150
- #
151
- # Assuming an api where each resource is namespaced with 'api/v1' and where
152
- # the url http://www.example.com/api/v1/foo/99 responds with the following.
153
- #
154
- # Header:
155
- #
156
- # Content-Type: application/json
157
- #
158
- # Body:
159
- #
160
- # {
161
- # "name": "Foo Bar"
162
- # }
163
- #
164
- # == Example
165
- #
166
- # class ExampleApi < HttpMagic::Api
167
- # url 'www.example.com'
168
- # namespace 'api/v1'
169
- # end
170
- #
171
- # ExampleApi.foo[99].get
172
- # => { "name" => "Foo Bar" }
173
- def get
174
- request = Request.new(@uri,
175
- headers: @headers
176
- )
177
- request.get
178
- end
179
-
180
- # POST's a resource from the URI and returns the result based on its content
181
- # type. JSON content will be parsed and returned as equivalent Ruby objects.
182
- # All other content types will be returned as text.
183
- #
184
- # Assuming an api where each resource is namespaced with 'api/v1' and where
185
- # the url http://www.example.com/api/v1/foo/create responds with the
186
- # following when a 'name' is sent with the request.
187
- #
188
- # Header:
189
- #
190
- # Content-Type: application/json
191
- #
192
- # Body:
193
- #
194
- # {
195
- # "name": "New Foo"
196
- # }
197
- #
198
- # == Example
199
- #
200
- # class ExampleApi < HttpMagic::Api
201
- # url 'www.example.com'
202
- # namespace 'api/v1'
203
- # end
204
- #
205
- # ExampleApi.foo.create.post(name: 'New Foo')
206
- # => { "name" => "New Foo" }
207
- def post(data = {})
208
- request = Request.new(@uri,
209
- headers: @headers,
210
- data: data,
211
- )
212
- request.post
213
- end
214
-
215
- def put(data = {})
216
- request = Request.new(@uri,
217
- headers: @headers,
218
- data: data,
219
- )
220
- request.put
221
- end
222
-
223
- # Instance scoped method_missing that accumulates the URN parts used in
224
- # forming the URI. It returns a reference to the current instance so that
225
- # method and [] based parts can be chained together to from the URN. In the
226
- # case of ExampleApi.foo[99] the 'foo' method is accumlated as a URN part
227
- # that will form the resulting URI.
228
- def method_missing(part, *args, &block)
229
- @uri.parts << part.to_s
230
- self
231
- end
232
- end
233
- end
@@ -1,93 +0,0 @@
1
- require 'net/http'
2
- require 'json'
3
-
4
- module HttpMagic
5
- # Encapsulating class to hold all of the infrastructure to make the actual
6
- # requests to the api. It receives at a minimum a HttpMagic::Uri object which
7
- # manages the url building.
8
- #
9
- # == Example
10
- #
11
- # uri_object = HttpMagic::Uri.new('http://example.com')
12
- #
13
- # request = Request.new(uri_object)
14
- #
15
- # request.get
16
- # => { 'name' => 'Foo Bar' }
17
- class Request
18
- def initialize(uri, options = {})
19
- @uri = uri
20
- @data = options[:data]
21
- @options = {
22
- headers: options[:headers] || {}
23
- }
24
- end
25
-
26
- def delete
27
- parse_response http.delete(@uri.urn, @options[:headers])
28
- end
29
-
30
- # Makes a GET request to the url provided by the Uri object and returns the
31
- # resulting JSON data as a Ruby hash.
32
- #
33
- # == Example
34
- #
35
- # uri_object = HttpMagic::Uri.new('http://example.com')
36
- #
37
- # request = Request.new(uri_object)
38
- #
39
- # request.get
40
- # => { 'name' => 'Foo Bar' }
41
- def get
42
- parse_response http.request_get(@uri.urn, @options[:headers])
43
- end
44
-
45
- # Makes a POST request to the url provided by the Uri object and returns the
46
- # resulting JSON data as a Ruby hash. If data was provided as an optional
47
- # initialization parameter, then that is also POSTed.
48
- #
49
- # == Example
50
- #
51
- # uri_object = HttpMagic::Uri.new('http://example.com')
52
- #
53
- # request = Request.new(uri_object, data: { name: 'New Foo' })
54
- #
55
- # request.post
56
- def post
57
- if !@data.empty?
58
- @options[:headers].merge!( 'Content-Type' => 'application/json' )
59
- end
60
-
61
- parse_response http.request_post(@uri.urn, @data.to_json, @options[:headers])
62
- end
63
-
64
- def put
65
- if !@data.empty?
66
- @options[:headers].merge!( 'Content-Type' => 'application/json' )
67
- end
68
-
69
- parse_response http.request_put(@uri.urn, @data.to_json, @options[:headers])
70
- end
71
-
72
- private
73
-
74
- def http
75
- return @http unless @http.nil?
76
- @http = Net::HTTP.new(@uri.domain, 443)
77
- @http.use_ssl = true
78
- @http
79
- end
80
-
81
- def parse_response(response)
82
- if response && response.is_a?(Net::HTTPSuccess)
83
- if response.body && response.content_type == 'application/json'
84
- JSON.parse(response.body)
85
- else
86
- response.body.to_s
87
- end
88
- else
89
- nil
90
- end
91
- end
92
- end
93
- end
@@ -1,74 +0,0 @@
1
-
2
- module HttpMagic
3
- # Helper class that holds the parts of the URI and provides methods to put
4
- # them together.
5
- #
6
- # == Example
7
- #
8
- # uri = HttpMagic::Uri.new('example.com')
9
- # uri.build
10
- # => "https://example.com/"
11
- #
12
- # uri.namespace = 'api/v2'
13
- # uri.build
14
- # => "https://example.com/api/v2"
15
- #
16
- # uri.parts = ['path']
17
- # uri.build
18
- # => "https://example.com/api/v2/path"
19
- #
20
- class Uri
21
- attr_accessor :namespace, :parts
22
-
23
- attr_reader :domain
24
-
25
- def initialize(domain)
26
- @domain = domain
27
- @parts = []
28
- end
29
-
30
- # Builds a full uniform resource identifier.
31
- #
32
- # == Example
33
- #
34
- # uri = HttpMagic::Uri.new('example.com')
35
- # uri.namespace = 'api/v1'
36
- # uri.parts = %w(foo bar)
37
- #
38
- # uri.urn
39
- # => "https://example.com/api/v1/foo/bar"
40
- def build
41
- "#{url}#{urn}"
42
- end
43
-
44
- # Uniform resource locator based on @domain value.
45
- #
46
- # == Example
47
- #
48
- # uri = HttpMagic::Uri.new('example.com')
49
- #
50
- # uri.url
51
- # => "https://example.com/"
52
- #
53
- # uri.url(false)
54
- # => "https://example.com"
55
- def url
56
- "https://#{@domain}"
57
- end
58
-
59
- # Uniform resource name for a resource.
60
- #
61
- # == Example
62
- #
63
- # uri = HttpMagic::Uri.new('example.com')
64
- # uri.namespace = 'api/v1'
65
- # uri.parts = %w(foo bar)
66
- #
67
- # uri.urn
68
- # => "/api/v1/foo/bar"
69
- def urn
70
- resource_name = [@namespace, @parts].flatten.compact.join('/')
71
- "/#{resource_name}"
72
- end
73
- end
74
- end
@@ -1,68 +0,0 @@
1
- require 'test_helper'
2
- require 'http_magic'
3
-
4
- class HttpMagicTest < HttpMagic::Api
5
- end
6
-
7
- describe 'HttpMagic#get' do
8
- before do
9
- @url = HttpMagicTest.url 'www.example.com'
10
- HttpMagicTest.namespace nil
11
- HttpMagicTest.headers nil
12
- end
13
-
14
- it 'should return the root response' do
15
- stub_request(:get, "https://#{@url}:443").
16
- to_return(body: 'I am root!!')
17
-
18
- assert_equal(
19
- 'I am root!!',
20
- HttpMagicTest.get
21
- )
22
- end
23
-
24
- it 'should return the named resource' do
25
- stub_request(:get, "https://#{@url}:443/bar").
26
- to_return(body: 'A bear walked into a bar...')
27
-
28
- assert_equal(
29
- 'A bear walked into a bar...',
30
- HttpMagicTest.bar.get
31
- )
32
- end
33
-
34
- it 'should return the named resource' do
35
- stub_request(:get, "https://#{@url}:443/bar/84").
36
- to_return(body: 'Where Everybody Knows Your Name')
37
-
38
- assert_equal(
39
- 'Where Everybody Knows Your Name',
40
- HttpMagicTest.bar[84].get
41
- )
42
- end
43
-
44
- it 'should serialize JSON objects' do
45
- stub_request(:get, "https://#{@url}:443/bar/99").
46
- to_return(
47
- headers: { 'Content-Type' => 'application/json' },
48
- body: fixture_file('projects.json')
49
- )
50
-
51
- assert_equal(
52
- 'GradesFirst',
53
- HttpMagicTest.bar[99].get.first['name']
54
- )
55
- end
56
-
57
- it 'should provide specified headers' do
58
- stub_request(:get, "https://#{@url}:443/bar/84").
59
- with(headers: { 'X-AuthToken' => 'test_token' }).
60
- to_return(body: 'Where Everybody Knows Your Name')
61
-
62
- HttpMagicTest.headers({ 'X-AuthToken' => 'test_token' })
63
- assert_equal(
64
- 'Where Everybody Knows Your Name',
65
- HttpMagicTest.bar[84].get
66
- )
67
- end
68
- end
@@ -1,34 +0,0 @@
1
- require 'test_helper'
2
- require 'http_magic'
3
-
4
- class HttpMagicTest < HttpMagic::Api
5
- end
6
-
7
- describe 'HttpMagic#post' do
8
- before do
9
- @url = HttpMagicTest.url 'www.example.com'
10
- HttpMagicTest.namespace nil
11
- HttpMagicTest.headers nil
12
- end
13
-
14
- it 'should send POST request' do
15
- stub_post = stub_request(:post, "https://#{@url}")
16
-
17
- HttpMagicTest.post
18
- assert_requested stub_post
19
- end
20
-
21
- it 'should send data with POST request' do
22
- expected_data = {
23
- apple: 'sauce',
24
- banana: 'bread'
25
- }
26
- stub_post = stub_request(:post, "https://#{@url}/foo").with(
27
- body: expected_data
28
- )
29
-
30
- HttpMagicTest.foo.post(expected_data)
31
-
32
- assert_requested stub_post
33
- end
34
- end
@@ -1,63 +0,0 @@
1
- require 'test_helper'
2
- require 'http_magic/uri'
3
- require 'http_magic/request'
4
-
5
- describe 'HttpMagic::Request' do
6
- before do
7
- @domain = 'example.com'
8
- @uri = HttpMagic::Uri.new(@domain)
9
- end
10
-
11
- it 'should make a request' do
12
- stub_request = stub_request(
13
- :get,
14
- "https://#{@domain}/api/v2/path/to/something"
15
- )
16
-
17
- @uri.namespace = 'api/v2'
18
- @uri.parts = ['path', 'to', 'something']
19
- request = HttpMagic::Request.new(@uri)
20
- request.get
21
-
22
- assert_requested stub_request
23
- end
24
-
25
- it 'should return content on request' do
26
- content = 'This is SPARTA!'
27
- stub_request(:get, "https://#{@domain}").
28
- to_return(body: content)
29
-
30
- request = HttpMagic::Request.new(@uri)
31
-
32
- assert_equal content, request.get
33
- end
34
-
35
- it 'should be able to post data as hash' do
36
- expected_data = {
37
- apple: 'crispy',
38
- banana: 'soft'
39
- }
40
- stub_request = stub_request(:post, "https://#{@domain}").with(
41
- body: expected_data.to_json,
42
- headers: { 'content-type' => 'application/json' }
43
- )
44
-
45
- request = HttpMagic::Request.new(@uri, data: expected_data)
46
- request.post
47
-
48
- assert_requested stub_request
49
- end
50
-
51
- it 'should set correct headers' do
52
- stub_request = stub_request(:get, "https://#{@domain}").
53
- with(headers: { 'X-AuthToken' => 'test_token' })
54
-
55
- request = HttpMagic::Request.new(
56
- @uri,
57
- headers: { 'X-AuthToken' => 'test_token' }
58
- )
59
- request.get
60
-
61
- assert_requested stub_request
62
- end
63
- end
@@ -1,49 +0,0 @@
1
- require 'test_helper'
2
- require 'http_magic/uri'
3
-
4
- describe 'HttpMagic::Uri' do
5
- before do
6
- @domain = 'example.com'
7
- @uri = uri = HttpMagic::Uri.new(@domain)
8
- end
9
-
10
- it 'must have a domain param' do
11
- assert_raises ArgumentError do
12
- HttpMagic::Uri.new
13
- end
14
- end
15
-
16
- it 'should return the domain' do
17
- assert_equal @domain, @uri.domain
18
- end
19
-
20
- it 'can build a simple uri' do
21
- assert_equal "https://#{@domain}/", @uri.build
22
- end
23
-
24
- it 'should have url' do
25
- assert_equal "https://#{@domain}", @uri.url
26
- end
27
-
28
- it 'should create urn with parts' do
29
- @uri.parts = ['path', 'to', 'something']
30
- assert_equal '/path/to/something', @uri.urn
31
- end
32
-
33
- it 'should create urn with namespace' do
34
- @uri.namespace = 'api/v2'
35
- assert_equal '/api/v2', @uri.urn
36
- end
37
-
38
- it 'should create urn with namespace and parts combined' do
39
- @uri.parts = ['path', 'to', 'something']
40
- @uri.namespace = 'api/v2'
41
- assert_equal '/api/v2/path/to/something', @uri.urn
42
- end
43
-
44
- it 'should create the full uri with urn included' do
45
- @uri.parts = ['path', 'to', 'something']
46
- @uri.namespace = 'api/v2'
47
- assert_equal "https://#{@domain}/api/v2/path/to/something", @uri.build
48
- end
49
- end