nexusmotion 0.0.1.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 74f602f6c45f8a521b460a0280c66f7c3e68fb06
4
+ data.tar.gz: cd0d0fbc7655bc274186ad21cadb694b218cd54a
5
+ SHA512:
6
+ metadata.gz: 4db5931b35c058eb686fd1a42373aaf46b5e6286cb498e904341a8c2737e78026e329820fccd6ba63f1f4498a1828e7e9d6cced4a7fc1ba18233c644122300e5
7
+ data.tar.gz: ba88f55fc1798b5468621691b955fc87a74778745f12b0fba17452eaeb90db3d33264a5db1d4e3d4d33a494feb1f0fe147c060bb86109e788f6c301b0384c008
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nexusmotion.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TigerWolf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Nexusmotion
2
+
3
+ This is an experimental **beta** gem for [RubyMotion Android](http://blog.rubymotion.com/post/87048665656/rubymotion-3-0-sneak-peek-android-support) that does simple HTTP POST and GET requests.
4
+
5
+ This gem will change quite a lot. There are methods that are not implemented (e.g. Thread.value) in RubyMotion or bugs that make some things difficult at the moment but will improve as new beta versions are released and will be added to this gem.
6
+
7
+ Please read [TODO & KNOWN ISSUES](TODO & KNOWN ISSUES.md)
8
+
9
+ Be warned: This gem will change as new versions come out to use new features implemented.
10
+
11
+ Please feel free to send suggestions or pull requests.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'nexusmotion'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install nexusmotion
28
+
29
+ ## Usage
30
+
31
+ See https://github.com/TigerWolf/TestBed for example usage.
32
+
33
+ ```
34
+ c = Nexusmotion::Client.new
35
+ url = "https://posttestserver.com/post.php?dir=nexusmotion"
36
+ data = [["id", 33443]]
37
+ result = c.post(url, data)
38
+ puts result
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/[my-github-username]/nexusmotion/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,11 @@
1
+ TODO
2
+ ----
3
+
4
+ * Test performance of threads in Android against RubyMotion thread and pick one once exceptions are fixed in RM
5
+ * Add seperate methods for both get and post.
6
+
7
+ KNOWN ISSUES
8
+ -----------
9
+
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
@@ -0,0 +1,23 @@
1
+ module Nexusmotion
2
+ class Client
3
+ def post(url, data=[])
4
+ begin
5
+ finished = false
6
+ tr = Thread.start{
7
+ runner = Nexusmotion::GapJunction.new
8
+ runner.url = url
9
+ runner.data = data
10
+ s = runner.run
11
+ # Thread.current["result"] = s # []= is not yet defined
12
+ }
13
+ tr.join
14
+ finished = true
15
+ result = Nexusmotion::GlobalResult.result
16
+ Nexusmotion::GlobalResult.result = nil
17
+ result
18
+ rescue Exception => e
19
+ p "An error occurred: #{e.inspect}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,7 @@
1
+ class Error < Exception
2
+ attr_accessor :message, :code
3
+ def initialize(code, msg)
4
+ self.message = msg
5
+ self.code = code
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ module Nexusmotion
2
+ class GapJunction
3
+ def run
4
+ result = ""
5
+
6
+ begin
7
+ # Default Values
8
+ @url ||= "http://httpbin.org/post"
9
+ @data ||= []
10
+
11
+ httpclient = Org::Apache::Http::Impl::Client::DefaultHttpClient.new
12
+ httppost = Org::Apache::Http::Client::Methods::HttpPost.new(@url);
13
+
14
+ nameValuePairs = []
15
+ @data.each do |key, value|
16
+ nameValuePairs.add(Org::Apache::Http::Message::BasicNameValuePair.new(key, value))
17
+ end
18
+
19
+ httppost.setEntity(Org::Apache::Http::Client::Entity::UrlEncodedFormEntity.new(nameValuePairs));
20
+
21
+ response = httpclient.execute(httppost);
22
+
23
+ result = inputStreamToString(response.getEntity().getContent()).toString()
24
+
25
+ rescue Java::Net::ConnectException => e
26
+ message = "There was problem with the connection."
27
+ # error = Nexusmotion::Error.new(nil, message)
28
+ #raise error
29
+ p message
30
+ rescue Exception => e
31
+ message = "Unknown error. Error: #{e.inspect}"
32
+ # error = Nexusmotion::Error.new(nil, message)
33
+ #raise error
34
+ p message
35
+ end
36
+ Nexusmotion::GlobalResult.result = result
37
+ result # This will not be returned/used for now, but possibly in the future.
38
+ end
39
+
40
+ def url=(url)
41
+ @url = url
42
+ end
43
+
44
+ def data=(data)
45
+ @data = data
46
+ end
47
+
48
+ 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
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,3 @@
1
+ module Nexusmotion
2
+ VERSION = "0.0.1.beta"
3
+ end
@@ -0,0 +1,30 @@
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
9
+ end
10
+
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)
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nexusmotion/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nexusmotion"
8
+ spec.version = Nexusmotion::VERSION
9
+ spec.authors = ["TigerWolf"]
10
+ spec.email = ["hiddentiger@gmail.com"]
11
+ spec.summary = %q{A RubyMotion Android gem to provide basic HTTP like GET and POST.}
12
+ spec.description = %q{An experimental gem to provide basic HTTP networking for Rubymotion Android.
13
+ It wraps Android networking classes to provide an easy way to make GET and POST requests }
14
+ spec.homepage = "https://github.com/TigerWolf/nexusmotion"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nexusmotion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta
5
+ platform: ruby
6
+ authors:
7
+ - TigerWolf
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: "An experimental gem to provide basic HTTP networking for Rubymotion
42
+ Android.\n It wraps Android networking classes to provide an easy way to make
43
+ GET and POST requests "
44
+ email:
45
+ - hiddentiger@gmail.com
46
+ executables: []
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - TODO & KNOWN ISSUES.md
56
+ - lib/nexusmotion.rb
57
+ - lib/nexusmotion/client.rb
58
+ - lib/nexusmotion/error.rb
59
+ - lib/nexusmotion/gap_junction.rb
60
+ - lib/nexusmotion/global_result.rb
61
+ - lib/nexusmotion/version.rb
62
+ - nexusmotion.gemspec
63
+ homepage: https://github.com/TigerWolf/nexusmotion
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">"
79
+ - !ruby/object:Gem::Version
80
+ version: 1.3.1
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A RubyMotion Android gem to provide basic HTTP like GET and POST.
87
+ test_files: []