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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad2cd08d42a11bcf46807174165e4136d540af9d
4
- data.tar.gz: c5a7818df0bdf4e951ed96d94087860d5a9ddd2c
3
+ metadata.gz: 4ec3cc8e9520b1d9e669f738f1ab9b4f9f06db4c
4
+ data.tar.gz: 122ff846beebf6820548c8998e754d0fc9fb5c51
5
5
  SHA512:
6
- metadata.gz: 3f06303d91f79a4f6b8acaed5596ceb1ce09c4abd7c881ba25e864419d4ad71099619cda03d75f9456e74c3f49f07f176b8b8c4bf74e595de4e745482d540cef
7
- data.tar.gz: 5f4de7f4649eaa3502910acce8538817a9e10e65beb369f36a68becf92589c59ce5f1a4c7624134eac5aab720deabada196b92a21ed7af999f6ca2505802aed6
6
+ metadata.gz: eae94c4925d4ddba5af79cc38487417f2c640bde42df46efb2cbf70593a6d090db126355d1976d9bfa400a5cfca58f19bb14540cae0900744ff801b265ff03df
7
+ data.tar.gz: 16ffdcefe8e5ea5cd7c8eeb7791edd2c97437c4bcae90a531b82885f58e0b0ea1b87f23811089e603c394e97297334ee2fc2a91e6a145837c7cf025768954ea9
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ /build/
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in nexusmotion.gemspec
4
4
  gemspec
5
-
6
- gem 'bacon'
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.2.beta"
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
- Or install it yourself as:
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
@@ -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
@@ -1,30 +1,10 @@
1
- if defined?(Motion::Project::Config)
2
- def rubymotion_require(filename)
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
- require "nexusmotion/version"
12
- require "nexusmotion/client"
13
- require "nexusmotion/global_result"
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
+
@@ -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
- result = Nexusmotion::GlobalResult.result
16
- Nexusmotion::GlobalResult.result = nil
17
- result
28
+ result_object
18
29
  rescue Exception => e
19
- p "An error occurred: #{e.inspect}"
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
- # Default Values
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
- nameValuePairs = []
15
- @data.each do |key, value|
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
- httppost.setEntity(Org::Apache::Http::Client::Entity::UrlEncodedFormEntity.new(nameValuePairs));
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(httppost);
24
+ response = httpclient.execute(httrequest);
22
25
 
23
- result = inputStreamToString(response.getEntity().getContent()).toString()
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
- # error = Nexusmotion::Error.new(nil, message)
28
- #raise error
29
- p message
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
- # error = Nexusmotion::Error.new(nil, message)
33
- #raise error
34
- p message
39
+ @result_object.error = message
35
40
  end
36
- Nexusmotion::GlobalResult.result = result
37
- result # This will not be returned/used for now, but possibly in the future.
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
- line = ""
50
- total = Java::Lang::StringBuilder.new
51
- # Wrap a BufferedReader around the InputStream
52
- rd = Java::Io::BufferedReader.new(Java::Io::InputStreamReader.new(is))
53
- # Read response until the end
54
- while ((line = rd.readLine()) != nil) do
55
- total.append(line)
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
@@ -0,0 +1,16 @@
1
+ module Nexusmotion
2
+ class Result
3
+
4
+ attr_accessor :body, :error, :code
5
+
6
+ def success?
7
+ @error.nil?
8
+ end
9
+
10
+ def failure?
11
+ !success?
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Nexusmotion
2
- VERSION = "0.0.2.beta"
2
+ VERSION = "0.0.3.beta"
3
3
  end
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.2.beta
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-09 00:00:00.000000000 Z
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/global_result.rb
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.4.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