nexusmotion 0.0.2.beta → 0.0.3.beta
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/.gitignore +1 -0
- data/Gemfile +0 -2
- data/README.md +10 -5
- data/Rakefile +0 -44
- data/TODO & KNOWN ISSUES.md +16 -3
- data/lib/nexusmotion.rb +6 -26
- data/lib/nexusmotion/client.rb +16 -5
- data/lib/nexusmotion/gap_junction.rb +41 -29
- data/lib/nexusmotion/result.rb +16 -0
- data/lib/nexusmotion/version.rb +1 -1
- metadata +4 -4
- data/lib/nexusmotion/global_result.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ec3cc8e9520b1d9e669f738f1ab9b4f9f06db4c
|
4
|
+
data.tar.gz: 122ff846beebf6820548c8998e754d0fc9fb5c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eae94c4925d4ddba5af79cc38487417f2c640bde42df46efb2cbf70593a6d090db126355d1976d9bfa400a5cfca58f19bb14540cae0900744ff801b265ff03df
|
7
|
+
data.tar.gz: 16ffdcefe8e5ea5cd7c8eeb7791edd2c97437c4bcae90a531b82885f58e0b0ea1b87f23811089e603c394e97297334ee2fc2a91e6a145837c7cf025768954ea9
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ sudo motion update --pre
|
|
21
21
|
Add this line to your application's Gemfile:
|
22
22
|
|
23
23
|
```ruby
|
24
|
-
gem 'nexusmotion', ">= 0.0.
|
24
|
+
gem 'nexusmotion', ">= 0.0.3.beta"
|
25
25
|
```
|
26
26
|
|
27
27
|
Add this line in your rake file:
|
@@ -33,11 +33,14 @@ require 'nexusmotion'
|
|
33
33
|
|
34
34
|
And then execute:
|
35
35
|
|
36
|
-
$ bundle
|
36
|
+
$ "bundle install --path=vendor/bundler
|
37
37
|
|
38
|
-
|
38
|
+
> Note: For some reason it needs to be vendored to avoid a bug:
|
39
|
+
|
40
|
+
`E/com/yourcompany/testbed(24873): BUG: runtime.cpp:1611`
|
41
|
+
|
42
|
+
`E/com/yourcompany/testbed(24873): class 'com/yourcompany/testbed/Client' not precompiled`
|
39
43
|
|
40
|
-
$ gem install nexusmotion --pre
|
41
44
|
|
42
45
|
## Usage
|
43
46
|
|
@@ -48,7 +51,9 @@ See https://github.com/TigerWolf/TestBed for example usage.
|
|
48
51
|
url = "https://posttestserver.com/post.php?dir=nexusmotion"
|
49
52
|
data = [["id", 33443]]
|
50
53
|
result = c.post(url, data)
|
51
|
-
puts result
|
54
|
+
puts result.body
|
55
|
+
puts result.code
|
56
|
+
puts result.success?
|
52
57
|
```
|
53
58
|
|
54
59
|
## Contributing
|
data/Rakefile
CHANGED
@@ -1,54 +1,10 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
$:.unshift("/Library/RubyMotionPre/lib")
|
3
3
|
require 'motion/project/template/android'
|
4
|
-
require 'bundler'
|
5
4
|
Bundler.require(:development)
|
6
|
-
require 'bacon'
|
7
5
|
require "nexusmotion"
|
8
|
-
# require 'nexusmotion'
|
9
|
-
# require 'bacon'
|
10
|
-
|
11
|
-
# task :spec do
|
12
|
-
|
13
|
-
# Motion::Project::App.setup do |app|
|
14
|
-
# app.specs_dir = 'spec/'
|
15
|
-
# end
|
16
|
-
|
17
|
-
# #Dir.glob('./spec/**/*.rb').each {|file| require file }
|
18
|
-
# puts `bacon spec/*`
|
19
|
-
|
20
|
-
# # App.config.spec_mode = true
|
21
|
-
# # spec_files = App.config.spec_files - Dir.glob('./spec/**/*.rb')
|
22
|
-
# # App
|
23
|
-
# # App.config.instance_variable_set("@spec_files", spec_files)
|
24
|
-
# # bacon spec_files
|
25
|
-
# # Rake::Task["simulator"].invoke
|
26
|
-
|
27
|
-
# end
|
28
6
|
|
29
7
|
Motion::Project::App.setup do |app|
|
30
8
|
app.name = 'nexusmotion'
|
31
9
|
app.detect_dependencies = true
|
32
10
|
end
|
33
|
-
|
34
|
-
task :testing do
|
35
|
-
$:.unshift("/Library/RubyMotionPre/lib")
|
36
|
-
require 'motion/project/template/android'
|
37
|
-
require "nexusmotion"
|
38
|
-
require "nexusmotion/client"
|
39
|
-
require "nexusmotion/gap_junction"
|
40
|
-
require "nexusmotion/global_result"
|
41
|
-
require "webstub"
|
42
|
-
require 'bacon'
|
43
|
-
|
44
|
-
App.config_without_setup.spec_mode = true
|
45
|
-
# ENV['debug'] ||= '1'
|
46
|
-
# Rake::Task["device"].invoke
|
47
|
-
|
48
|
-
Bacon.summary_on_exit
|
49
|
-
files = Dir.glob('./spec/**/*.rb')
|
50
|
-
files.each { |file|
|
51
|
-
load file
|
52
|
-
}
|
53
|
-
|
54
|
-
end
|
data/TODO & KNOWN ISSUES.md
CHANGED
@@ -3,9 +3,22 @@ TODO
|
|
3
3
|
|
4
4
|
* Test performance of threads in Android against RubyMotion thread and pick one once exceptions are fixed in RM
|
5
5
|
* Add seperate methods for both get and post.
|
6
|
+
* Create a lock on the global result so multiple threads cannot modify (use Mutex http://www.ruby-doc.org/core-2.1.3/Mutex.html)
|
7
|
+
* Come up with another solution for .join so that thread does not block UI thread
|
8
|
+
* Try implementing ASync task in pure Android instead
|
9
|
+
* Try Executor
|
10
|
+
* Set timeout for netork request - customisable
|
11
|
+
* Create a configuration hash like other gems
|
12
|
+
* Implement Async Like https://github.com/typhoeus/typhoeus - implement a callback function that can be user defined (possibly updating the UI or similar.)
|
13
|
+
* Allow for checking of status - AsyncTask.Status.RUNNING
|
14
|
+
* As well as the callback - allow for a blocking call to get the response like Thread.new.join
|
15
|
+
|
16
|
+
Future Stuff
|
17
|
+
----
|
18
|
+
* Implement progress update - to allow for progress bar
|
19
|
+
* Implement onPreExecute for showing loading icon etc - possibly leave this up to the caller
|
20
|
+
* Implement cancel
|
6
21
|
|
7
22
|
KNOWN ISSUES
|
8
|
-
|
23
|
+
----
|
9
24
|
|
10
|
-
* If you make a request with an incorrect URL or one that doesnt respond then the app will crash
|
11
|
-
* Catch Android exceptions: http://hipbyte.myjetbrains.com/youtrack/issue/RM-618
|
data/lib/nexusmotion.rb
CHANGED
@@ -1,30 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
@files_to_require ||= []
|
4
|
-
@files_to_require << filename
|
5
|
-
end
|
6
|
-
|
7
|
-
alias :old_require :require
|
8
|
-
alias :require :rubymotion_require
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
9
3
|
end
|
10
4
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
require "nexusmotion/gap_junction"
|
15
|
-
require "nexusmotion/error"
|
16
|
-
|
17
|
-
if defined?(Motion::Project::Config)
|
18
|
-
# Revert normal require
|
19
|
-
alias :require :old_require
|
20
|
-
|
21
|
-
Motion::Project::App.setup do |app|
|
22
|
-
# prepare full paths of files that will be compiled
|
23
|
-
paths_to_require = @files_to_require.map do |file|
|
24
|
-
File.join(File.dirname(__FILE__), file + ".rb")
|
25
|
-
end
|
26
|
-
|
27
|
-
# add paths in correct order
|
28
|
-
app.files.unshift(*paths_to_require)
|
5
|
+
Motion::Project::App.setup do |app|
|
6
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'nexusmotion/*.rb')).each do |file|
|
7
|
+
app.files.unshift(file)
|
29
8
|
end
|
30
9
|
end
|
10
|
+
|
data/lib/nexusmotion/client.rb
CHANGED
@@ -1,22 +1,33 @@
|
|
1
1
|
module Nexusmotion
|
2
2
|
class Client
|
3
|
-
def post(url, data
|
3
|
+
def post(url, data)
|
4
|
+
method = :post
|
5
|
+
request(method, url, data)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(url)
|
9
|
+
method = :get
|
10
|
+
request(method, url)
|
11
|
+
end
|
12
|
+
|
13
|
+
def request(method, url, data=[])
|
4
14
|
begin
|
5
15
|
finished = false
|
16
|
+
result_object = Nexusmotion::Result.new
|
6
17
|
tr = Thread.start{
|
7
18
|
runner = Nexusmotion::GapJunction.new
|
19
|
+
runner.result_object = result_object
|
8
20
|
runner.url = url
|
9
21
|
runner.data = data
|
22
|
+
runner.method = method
|
10
23
|
s = runner.run
|
11
24
|
# Thread.current["result"] = s # []= is not yet defined
|
12
25
|
}
|
13
26
|
tr.join
|
14
27
|
finished = true
|
15
|
-
|
16
|
-
Nexusmotion::GlobalResult.result = nil
|
17
|
-
result
|
28
|
+
result_object
|
18
29
|
rescue Exception => e
|
19
|
-
|
30
|
+
result_object.error = e
|
20
31
|
end
|
21
32
|
end
|
22
33
|
end
|
@@ -1,40 +1,47 @@
|
|
1
1
|
module Nexusmotion
|
2
2
|
class GapJunction
|
3
|
+
|
3
4
|
def run
|
4
|
-
result = ""
|
5
5
|
|
6
6
|
begin
|
7
|
-
|
8
|
-
@url ||= "http://httpbin.org/post"
|
7
|
+
@url ||= ""
|
9
8
|
@data ||= []
|
10
9
|
|
11
10
|
httpclient = Org::Apache::Http::Impl::Client::DefaultHttpClient.new
|
12
|
-
httppost = Org::Apache::Http::Client::Methods::HttpPost.new(@url);
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
nameValuePairs.add(Org::Apache::Http::Message::BasicNameValuePair.new(key, value))
|
17
|
-
end
|
12
|
+
if @method == :post
|
13
|
+
httrequest = Org::Apache::Http::Client::Methods::HttpPost.new(@url);
|
18
14
|
|
19
|
-
|
15
|
+
nameValuePairs = []
|
16
|
+
@data.each do |key, value|
|
17
|
+
nameValuePairs.add(Org::Apache::Http::Message::BasicNameValuePair.new(key, value))
|
18
|
+
end
|
19
|
+
httrequest.setEntity(Org::Apache::Http::Client::Entity::UrlEncodedFormEntity.new(nameValuePairs));
|
20
|
+
else
|
21
|
+
httrequest = Org::Apache::Http::Client::Methods::HttpGet.new(@url);
|
22
|
+
end
|
20
23
|
|
21
|
-
response = httpclient.execute(
|
24
|
+
response = httpclient.execute(httrequest);
|
22
25
|
|
23
|
-
|
26
|
+
response_stream = response.entity
|
27
|
+
status_line = response.statusLine
|
28
|
+
body = inputStreamToString(response_stream.content).toString
|
29
|
+
code = status_line.statusCode
|
24
30
|
|
25
31
|
rescue Java::Net::ConnectException => e
|
26
32
|
message = "There was problem with the connection."
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
@result_object.error = message
|
34
|
+
rescue Java::Net::UnknownHostException => e
|
35
|
+
message = "Unknown host. Unable to resolve the hostname."
|
36
|
+
@result_object.error = message
|
30
37
|
rescue Exception => e
|
31
38
|
message = "Unknown error. Error: #{e.inspect}"
|
32
|
-
|
33
|
-
#raise error
|
34
|
-
p message
|
39
|
+
@result_object.error = message
|
35
40
|
end
|
36
|
-
|
37
|
-
|
41
|
+
|
42
|
+
@result_object.code = code
|
43
|
+
@result_object.body = body
|
44
|
+
# @result_object # This will not be returned/used for now, but possibly in the future.
|
38
45
|
end
|
39
46
|
|
40
47
|
def url=(url)
|
@@ -45,17 +52,22 @@ module Nexusmotion
|
|
45
52
|
@data = data
|
46
53
|
end
|
47
54
|
|
55
|
+
def method=(method)
|
56
|
+
@method = method
|
57
|
+
end
|
58
|
+
|
59
|
+
def result_object=(result_object)
|
60
|
+
@result_object = result_object
|
61
|
+
end
|
62
|
+
|
48
63
|
def inputStreamToString(is)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
# Return full string
|
58
|
-
total
|
64
|
+
line = ""
|
65
|
+
total = Java::Lang::StringBuilder.new
|
66
|
+
rd = Java::Io::BufferedReader.new(Java::Io::InputStreamReader.new(is))
|
67
|
+
while ((line = rd.readLine()) != nil) do
|
68
|
+
total.append(line)
|
69
|
+
end
|
70
|
+
total
|
59
71
|
end
|
60
72
|
|
61
73
|
end
|
data/lib/nexusmotion/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexusmotion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TigerWolf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -57,7 +57,7 @@ files:
|
|
57
57
|
- lib/nexusmotion/client.rb
|
58
58
|
- lib/nexusmotion/error.rb
|
59
59
|
- lib/nexusmotion/gap_junction.rb
|
60
|
-
- lib/nexusmotion/
|
60
|
+
- lib/nexusmotion/result.rb
|
61
61
|
- lib/nexusmotion/version.rb
|
62
62
|
- nexusmotion.gemspec
|
63
63
|
homepage: https://github.com/TigerWolf/nexusmotion
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: 1.3.1
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.2.2
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A RubyMotion Android gem to provide basic HTTP like GET and POST.
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Nexusmotion
|
2
|
-
# This is not thread save, when we have thread responses implemented in RubyMotion we can use then instead
|
3
|
-
class GlobalResult
|
4
|
-
class << self
|
5
|
-
attr_accessor :result
|
6
|
-
def self.result=( result )
|
7
|
-
@result = result
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|