motion-http 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38301fffb680c2ff73c68cc0cafef260be772a4c09892c8f6706bb415014bdc6
4
- data.tar.gz: 562ac8347a504aa3c061beeb6555ec54b73d0ec5c6d27266349150c1e4239c45
3
+ metadata.gz: 88e08d0e8132c9c56a98c4c06ab626ae647ea17818edb12bcfb0fc3d07f6b091
4
+ data.tar.gz: ea9eb01732c98423f6e109fe51b3cb925f63d620cbbd9a13304f955a116ccf84
5
5
  SHA512:
6
- metadata.gz: d34d53372cd85ff50915ca586a36fdba710852a62e9f60c511139d0d72887084e974cc7a39faedc02a5737c96d858900e66ef661960572c22970aebccc613e32
7
- data.tar.gz: 01d2e62e89ed670128c423c4f005383cc2ff46e351c3dc2163cf567a88ee7a5507257c3321cac4ba151f1bb91f2865af9ebd4ce1aae9f0c06b369d46ba63117a
6
+ metadata.gz: ac6c4d219bba2251d9361465a4f755d483ee2625d399e92c7e9809c3f269905184d764bdda3b26d0d949161763e84c30b15a45d8bed0295e36d50dd7377b8685
7
+ data.tar.gz: 43b654efcb82dd09d9822c3b7a7dd328077978aa25b40c247f69d48b1e5bfc3e9c5d419272ac9036177ee02046c6af71733a54737530491905cce7b3b6fac568
data/README.md CHANGED
@@ -6,9 +6,9 @@ Supported platforms:
6
6
  - iOS, macOS, tvOS, watchOS
7
7
  - Android
8
8
 
9
- On Android, this gem depends on the super popular [OkHttp](http://square.github.io/okhttp/) networking library.
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 note that this library is still a work in progress. Please report bugs and suggestions for improvement!
11
+ Please report any bugs and suggestions for improvement!
12
12
 
13
13
  ## Installation
14
14
 
@@ -19,13 +19,17 @@ Add this line to your application's Gemfile:
19
19
  And then execute:
20
20
 
21
21
  $ bundle
22
- $ rake gradle:install # for Android apps
22
+ $ rake gradle:install # Android only
23
23
 
24
24
  ### iOS Specific Configuration
25
25
 
26
- If you will be making insecure HTTP requests (not HTTPS), you will need to explicitly allow insecure HTTP requests by adding this line to your app's configuration in your Rakefile:
26
+ If you will be making insecure requests (not using HTTPS), you will need to explicitly allow insecure HTTP requests by adding this line to your app's configuration (in your `Rakefile`). You might want to do this if you are trying to access localhost in development.
27
27
 
28
- app.info_plist['NSAppTransportSecurity'] = { 'NSAllowsArbitraryLoads' => true }
28
+ ```ruby
29
+ app.development do
30
+ app.info_plist['NSAppTransportSecurity'] = { 'NSAllowsArbitraryLoads' => true }
31
+ end
32
+ ```
29
33
 
30
34
  ## Usage
31
35
 
@@ -202,12 +206,37 @@ HTTP.logger.disable!
202
206
  4. Push to the branch (`git push origin my-new-feature`)
203
207
  5. Create new Pull Request
204
208
 
205
- ## MIT License
209
+ ## License
206
210
 
207
- Copyright 2018 Andrew Havens
211
+ Copyright 2018-2019 Andrew Havens
208
212
 
209
213
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
210
214
 
211
215
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
212
216
 
213
217
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
218
+
219
+ Parts of the source are under the following license:
220
+
221
+ Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
222
+ All rights reserved.
223
+
224
+ Redistribution and use in source and binary forms, with or without
225
+ modification, are permitted provided that the following conditions are met:
226
+
227
+ 1. Redistributions of source code must retain the above copyright notice, this
228
+ list of conditions and the following disclaimer.
229
+ 2. Redistributions in binary form must reproduce the above copyright notice,
230
+ this list of conditions and the following disclaimer in the documentation
231
+ and/or other materials provided with the distribution.
232
+
233
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
234
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
235
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
236
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
237
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
238
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
239
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
240
+ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
241
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
242
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,3 +1,26 @@
1
+ # Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
2
+ # All rights reserved.
3
+
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+
7
+ # 1. Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+
13
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
1
24
  # Copied from https://github.com/HipByte/Flow/blob/44283b31a63bc826d2c068557b6357dc1195680b/flow/base64/android/base64.rb
2
25
  class Base64
3
26
  def self.encode(string)
@@ -1,3 +1,26 @@
1
+ # Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
2
+ # All rights reserved.
3
+
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+
7
+ # 1. Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+
13
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
1
24
  # NOTE: Copied from https://github.com/HipByte/Flow/blob/master/flow/json/android/json.rb
2
25
  class JSON
3
26
  def self.parse(str)
@@ -1,3 +1,26 @@
1
+ # Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
2
+ # All rights reserved.
3
+
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+
7
+ # 1. Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+
13
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
1
24
  # Copied from https://github.com/HipByte/Flow/blob/44283b31a63bc826d2c068557b6357dc1195680b/flow/base64/cocoa/base64.rb
2
25
  class Base64
3
26
  def self.encode(string)
@@ -1,3 +1,27 @@
1
+ # Copyright (c) 2015-2016, HipByte (info@hipbyte.com) and contributors.
2
+ # All rights reserved.
3
+
4
+ # Redistribution and use in source and binary forms, with or without
5
+ # modification, are permitted provided that the following conditions are met:
6
+
7
+ # 1. Redistributions of source code must retain the above copyright notice, this
8
+ # list of conditions and the following disclaimer.
9
+ # 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ # this list of conditions and the following disclaimer in the documentation
11
+ # and/or other materials provided with the distribution.
12
+
13
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15
+ # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16
+ # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
17
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18
+ # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19
+ # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20
+ # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21
+ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
+
24
+ # Copied from https://github.com/HipByte/Flow/blob/44283b31a63bc826d2c068557b6357dc1195680b/flow/json/cocoa/json.rb
1
25
  class JSON
2
26
  def self.parse(json_string)
3
27
  error_ptr = Pointer.new(:id)
@@ -4,6 +4,7 @@ class Motion
4
4
  attr_reader :enabled
5
5
 
6
6
  def initialize(enabled = true)
7
+ # TODO: add ability to configure amount of logging (i.e. request URL only, no body, etc)
7
8
  @enabled = enabled
8
9
  end
9
10
 
@@ -15,63 +16,42 @@ class Motion
15
16
  @enabled = false
16
17
  end
17
18
 
19
+ def _logger
20
+ @_logger ||= Motion::Lager.new
21
+ end
22
+
23
+ def debug(message, color = :gray)
24
+ _logger.debug(message, color) if enabled
25
+ end
26
+
18
27
  def log(message, color = :white)
19
- puts colorize(color, message) if enabled
28
+ _logger.log(message, color) if enabled
20
29
  end
21
30
 
22
- def error(message)
23
- puts colorize(:red, message)
31
+ def error(message, color = :red)
32
+ _logger.error(message, color) # always log even if logging is disabled
24
33
  end
25
34
 
26
35
  def log_request(request)
27
- log "\nRequest:\n#{request.http_method.to_s.upcase} #{request.url}", :dark_gray
28
-
29
- if request.headers
30
- request.headers.each do |k,v|
31
- log "#{k}: #{v}", :dark_gray
32
- end
36
+ debug "\nRequest:\n#{request.http_method.to_s.upcase} #{request.url}"
37
+ request.headers.each do |k,v|
38
+ debug "#{k}: #{v}"
33
39
  end
34
-
35
- log(request.body, :dark_gray) if request.body
40
+ debug(request.body) if request.body
36
41
  end
37
42
 
38
43
  def log_response(response)
39
- log "\nResponse:", :dark_gray
44
+ debug "\nResponse:"
40
45
  if response.original_request
41
- log "URL: #{response.original_request.url}", :dark_gray
46
+ debug "URL: #{response.original_request.url}"
42
47
  end
43
- log "Status: #{response.status_code}", :dark_gray
48
+ debug "Status: #{response.status_code}"
44
49
  response.headers.each do |k,v|
45
- log "#{k}: #{v}", :dark_gray
50
+ debug "#{k}: #{v}"
46
51
  end
47
- log "\n#{response.body}", :dark_gray
52
+ debug("\n#{response.body}")
48
53
  end
49
54
 
50
- def colorize(color, string)
51
- return string unless simulator? # Only colorize in the simulator
52
-
53
- code = {
54
- red: 31,
55
- dark_gray: 90,
56
- }[color]
57
-
58
- if code
59
- "\e[#{code}m#{string}\e[0m"
60
- else
61
- string
62
- end
63
- end
64
-
65
- # Copied from https://github.com/rubymotion/BubbleWrap/blob/8eaf99a0966f2b375e774f5940279a704c10ad29/motion/core/ios/device.rb#L46
66
- def simulator?
67
- @simulator_state ||= begin
68
- if defined?(NSObject) # iOS
69
- !NSBundle.mainBundle.bundlePath.start_with?('/var/')
70
- else # android
71
- false
72
- end
73
- end
74
- end
75
55
  end
76
56
  end
77
57
  end
@@ -4,6 +4,8 @@ unless defined?(Motion::Project::Config)
4
4
  raise "This gem is only intended to be used in a RubyMotion project."
5
5
  end
6
6
 
7
+ require 'motion-lager'
8
+
7
9
  lib_dir_path = File.dirname(File.expand_path(__FILE__))
8
10
  Motion::Project::App.setup do |app|
9
11
  app.files.unshift(*Dir.glob(File.join(lib_dir_path, "common/**/*.rb")))
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Havens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-08-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: motion-lager
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: A cross-platform HTTP client for RubyMotion that's quick and easy to
14
28
  use.
15
29
  email:
@@ -35,7 +49,7 @@ files:
35
49
  - lib/common/http/request.rb
36
50
  - lib/common/http/response.rb
37
51
  - lib/motion-http.rb
38
- homepage: https://github.com/andrewhavens/motion-http
52
+ homepage: https://github.com/rubymotion-community/motion-http
39
53
  licenses:
40
54
  - MIT
41
55
  metadata: {}
@@ -54,8 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
68
  - !ruby/object:Gem::Version
55
69
  version: '0'
56
70
  requirements: []
57
- rubyforge_project:
58
- rubygems_version: 2.7.6
71
+ rubygems_version: 3.0.6
59
72
  signing_key:
60
73
  specification_version: 4
61
74
  summary: A cross-platform HTTP client for RubyMotion that's quick and easy to use.