motion-http 1.0.1 → 1.0.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 +4 -4
- data/README.md +32 -17
- data/lib/common/http/logger.rb +2 -3
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a2a08f70352d4ca6c4a4b3a79ab5825e806787ab90088bcad88350360d5c11f
|
4
|
+
data.tar.gz: 9bfc38b0f0138c7c4fb5ab98974ddb4ab852ed96e083d001ec683463d2e5f0ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a3d796b3c9654461fb66b42456e7f43bfd6d896e5d3f0165c5d00dcb184ca5867b55a089d2eb75d2508b76697bec120bc1047874bc02530cb5e0c93896aa2ec
|
7
|
+
data.tar.gz: caf9553c2567c658ffd23c303dba63014a30fba3f5f4f111339753a8bab2c4b8bb9dbde0aa39d0d2e4dbac689bb826e75760123b502411687c4ea93dcee8c7cf
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Supported platforms:
|
|
8
8
|
|
9
9
|
It makes use of the officially supported networking libraries provided by Apple and Google. The goal of this gem is to provide you with a stable alternative to using these libraries directly, using a syntax that is much easier to use.
|
10
10
|
|
11
|
-
Please report any bugs
|
11
|
+
Please report any bugs or suggestions for improvement!
|
12
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -33,9 +33,9 @@ end
|
|
33
33
|
|
34
34
|
## Usage
|
35
35
|
|
36
|
-
Using `motion-http` is quick and easy. You can
|
36
|
+
Using `motion-http` is quick and easy. You can either make one-off requests or create a reusable API client for further customization.
|
37
37
|
|
38
|
-
###
|
38
|
+
### Basic Usage
|
39
39
|
|
40
40
|
The basic syntax for a request looks like this:
|
41
41
|
```ruby
|
@@ -89,16 +89,25 @@ HTTP.get("http://api.example.com/people.json") do |response|
|
|
89
89
|
end
|
90
90
|
```
|
91
91
|
|
92
|
-
Use the `follow_redirects` option to specify whether or not to follow redirects.
|
92
|
+
Use the `follow_redirects` option to specify whether or not to follow redirects. The default is `true`:
|
93
93
|
```ruby
|
94
94
|
HTTP.get("http://example.com/redirect", follow_redirects: false) do |response|
|
95
95
|
# ...
|
96
96
|
end
|
97
97
|
```
|
98
98
|
|
99
|
-
|
99
|
+
#### POST Requests
|
100
|
+
|
101
|
+
When making a `POST` request, specifying the request body is easy:
|
102
|
+
```ruby
|
103
|
+
HTTP.post("http://www.example.com/endpoint", body: raw_request_body) do |response|
|
104
|
+
# ...
|
105
|
+
end
|
106
|
+
```
|
107
|
+
|
108
|
+
Specify the `:form` option and it will automatically be encoded as `application/x-www-form-urlencoded` request body:
|
100
109
|
```ruby
|
101
|
-
HTTP.post("http://www.example.com/login", form: { user: 'andrew',
|
110
|
+
HTTP.post("http://www.example.com/login", form: { user: 'andrew', password: 'secret'}) do |response|
|
102
111
|
if response.success?
|
103
112
|
puts "Authenticated!"
|
104
113
|
elsif response.client_error?
|
@@ -122,7 +131,7 @@ HTTP.post("http://www.example.com/widgets", json: { widget: { name: "Foobar" } }
|
|
122
131
|
end
|
123
132
|
```
|
124
133
|
|
125
|
-
|
134
|
+
To specify request specific headers, use the `:headers` option. This overrides any previously set headers. In this example, we override the default JSON content type:
|
126
135
|
```ruby
|
127
136
|
HTTP.post("http://www.example.com/widgets",
|
128
137
|
headers: { 'Content-Type' => 'application/vnd.api+json' },
|
@@ -134,12 +143,12 @@ end
|
|
134
143
|
|
135
144
|
All other HTTP method requests work the same way:
|
136
145
|
```ruby
|
137
|
-
HTTP.put(url,
|
138
|
-
HTTP.patch(url,
|
139
|
-
HTTP.delete(url,
|
140
|
-
HTTP.head(url,
|
141
|
-
HTTP.options(url,
|
142
|
-
HTTP.trace(url,
|
146
|
+
HTTP.put(url, options) { ... }
|
147
|
+
HTTP.patch(url, options) { ... }
|
148
|
+
HTTP.delete(url, options) { ... }
|
149
|
+
HTTP.head(url, options) { ... }
|
150
|
+
HTTP.options(url, options) { ... }
|
151
|
+
HTTP.trace(url, options) { ... }
|
143
152
|
```
|
144
153
|
|
145
154
|
### Advanced Usage
|
@@ -192,7 +201,13 @@ client.headers['Authorization'] = "Token token=#{my_token}"
|
|
192
201
|
|
193
202
|
### Logging
|
194
203
|
|
195
|
-
|
204
|
+
Logging is disabled by default. To enable logging:
|
205
|
+
|
206
|
+
```
|
207
|
+
HTTP.logger.enable!
|
208
|
+
```
|
209
|
+
|
210
|
+
To disable it again:
|
196
211
|
|
197
212
|
```
|
198
213
|
HTTP.logger.disable!
|
@@ -222,13 +237,13 @@ Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
|
|
222
237
|
All rights reserved.
|
223
238
|
|
224
239
|
Redistribution and use in source and binary forms, with or without
|
225
|
-
modification, are permitted provided that the following conditions are met:
|
240
|
+
modification, are permitted provided that the following conditions are met:
|
226
241
|
|
227
242
|
1. Redistributions of source code must retain the above copyright notice, this
|
228
|
-
list of conditions and the following disclaimer.
|
243
|
+
list of conditions and the following disclaimer.
|
229
244
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
230
245
|
this list of conditions and the following disclaimer in the documentation
|
231
|
-
and/or other materials provided with the distribution.
|
246
|
+
and/or other materials provided with the distribution.
|
232
247
|
|
233
248
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
234
249
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
data/lib/common/http/logger.rb
CHANGED
@@ -3,9 +3,8 @@ class Motion
|
|
3
3
|
class Logger
|
4
4
|
attr_reader :enabled
|
5
5
|
|
6
|
-
def initialize
|
7
|
-
|
8
|
-
@enabled = enabled
|
6
|
+
def initialize
|
7
|
+
@enabled = false # logging is disabled by default
|
9
8
|
end
|
10
9
|
|
11
10
|
def enable!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Havens
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: motion-lager
|
@@ -53,7 +53,7 @@ homepage: https://github.com/rubymotion-community/motion-http
|
|
53
53
|
licenses:
|
54
54
|
- MIT
|
55
55
|
metadata: {}
|
56
|
-
post_install_message:
|
56
|
+
post_install_message:
|
57
57
|
rdoc_options: []
|
58
58
|
require_paths:
|
59
59
|
- lib
|
@@ -68,8 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
|
-
rubygems_version: 3.
|
72
|
-
signing_key:
|
71
|
+
rubygems_version: 3.2.15
|
72
|
+
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: A cross-platform HTTP client for RubyMotion that's quick and easy to use.
|
75
75
|
test_files: []
|