motion-converser 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +1 -0
- data/lib/motion-converser.rb +1 -0
- data/lib/motion/project/converser.rb +73 -0
- data/motion-converser.gemspec +24 -0
- data/sample-app/.gitignore +15 -0
- data/sample-app/Gemfile +4 -0
- data/sample-app/Rakefile +15 -0
- data/sample-app/app/app_delegate.rb +8 -0
- data/sample-app/app/converser_view.rb +29 -0
- data/sample-app/app/converser_view_controller.rb +101 -0
- data/sample-app/resources/Default-568h@2x.png +0 -0
- data/sample-app/spec/main_spec.rb +9 -0
- data/sample-app/vendor/.gitkeep +0 -0
- metadata +101 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kevin Fagan
|
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,37 @@
|
|
1
|
+
RubyMotion-Converser
|
2
|
+
=================
|
3
|
+
|
4
|
+
Allows RubyMotion projects to easily embed the Converser SDK.
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
- RubyMotion 1.0 or greater (see http://www.rubymotion.com).
|
9
|
+
|
10
|
+
|
11
|
+
## Setup
|
12
|
+
|
13
|
+
1. Download the Converser SDK from http://converser.io/downloads/ and copy the `ios-converser-sdk` folder into `vendor` directory (or alternatively just create a symbolic link). Create the `vendor` directory if it does not exist. You should have something like this.
|
14
|
+
```
|
15
|
+
$ ls vendor/ios-converser-sdk
|
16
|
+
/ConverserResources/ libVGConversationKit_universal.a include/
|
17
|
+
```
|
18
|
+
|
19
|
+
2. Edit the `Rakefile` of your RubyMotion project and add the following require lines.
|
20
|
+
```ruby
|
21
|
+
require 'rubygems'
|
22
|
+
require 'motion-converser'
|
23
|
+
```
|
24
|
+
|
25
|
+
3. Still in the `Rakefile`, set up the `app_api_key`, `server_url` and `framework` variables in your application configuration block.
|
26
|
+
```ruby
|
27
|
+
Motion::Project::App.setup do |app|
|
28
|
+
# ...
|
29
|
+
app.converser.framework = 'vendor/ios-converser-sdk'
|
30
|
+
app.converser.app_api_key = 'APP API KEY'
|
31
|
+
app.converser.server_url = 'SERVER URL'
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
4. The `ConverserEngine` singleton is available from any class in your application. You access this singleton by calling the `ConverserEngine.instance` method.
|
36
|
+
|
37
|
+
5. See included sample-app for further information.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'motion/project/converser'
|
@@ -0,0 +1,73 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise 'This file must be required within a RubyMotion project Rakefile.'
|
3
|
+
end
|
4
|
+
|
5
|
+
class ConverserConfig
|
6
|
+
attr_accessor :framework, :server_url, :app_api_key
|
7
|
+
|
8
|
+
def initialize(config)
|
9
|
+
@config = config
|
10
|
+
end
|
11
|
+
|
12
|
+
def framework=(path)
|
13
|
+
if @framework != path
|
14
|
+
@config.unvendor_project(@framework)
|
15
|
+
@framework = path
|
16
|
+
@config.vendor_project(path, :static, :products => ['libVGConversationKit_universal.a'], :headers_dir => 'include')
|
17
|
+
@config.resources_dirs << "#{path}/ConverserResources"
|
18
|
+
@config.frameworks << 'MessageUI'
|
19
|
+
create_code
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def app_api_key=(app_api_key)
|
24
|
+
@app_api_key = app_api_key
|
25
|
+
create_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def server_url=(server_url)
|
29
|
+
@server_url = server_url
|
30
|
+
create_code
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def create_code
|
36
|
+
return unless @framework && @app_api_key && @server_url
|
37
|
+
code = <<EOF
|
38
|
+
# This file is automatically generated. Do not edit.
|
39
|
+
|
40
|
+
class ConverserEngine
|
41
|
+
def self.instance
|
42
|
+
Dispatch.once { @instance ||= VGConversationEngine.alloc.initWithHostName('#{@server_url}', andKey: '#{@app_api_key}') }
|
43
|
+
@instance
|
44
|
+
end
|
45
|
+
end
|
46
|
+
EOF
|
47
|
+
converser_file = './app/converser_code.rb'
|
48
|
+
create_stub(converser_file, code)
|
49
|
+
add_file(converser_file)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_stub(path, code)
|
53
|
+
if !File.exist?(path) or File.read(path) != code
|
54
|
+
File.open(path, 'w') { |io| io.write(code) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_file(path)
|
59
|
+
files = @config.files.flatten
|
60
|
+
@config.files << path unless files.find { |x| File.expand_path(x) == File.expand_path(path) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Motion
|
65
|
+
module Project
|
66
|
+
class Config
|
67
|
+
variable :converser
|
68
|
+
def converser
|
69
|
+
@converser ||= ConverserConfig.new(self)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
VERSION = 1.0
|
3
|
+
|
4
|
+
lib = File.expand_path('../lib', __FILE__)
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "motion-converser"
|
9
|
+
spec.version = VERSION
|
10
|
+
spec.authors = ["Kevin Fagan"]
|
11
|
+
spec.email = ["kevin.fagan1@gmail.com"]
|
12
|
+
spec.description = %q{Allows RubyMotion projects to easily embed the Converser SDK}
|
13
|
+
spec.summary = %q{Converser integration for RubyMotion projects}
|
14
|
+
spec.homepage = "https://github.com/kjf/RubyMotion-Converser"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split($/)
|
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.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/sample-app/Gemfile
ADDED
data/sample-app/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project/template/ios'
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
Bundler.setup
|
7
|
+
Bundler.require
|
8
|
+
|
9
|
+
Motion::Project::App.setup do |app|
|
10
|
+
# Use `rake config' to see complete project settings.
|
11
|
+
app.name = 'Converser Sample App'
|
12
|
+
|
13
|
+
app.converser.framework = 'vendor/ios-converser-sdk'
|
14
|
+
app.converser.app_api_key = 'Add you app api key here'
|
15
|
+
app.converser.server_url = 'Add the server url here'
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
3
|
+
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
|
4
|
+
@window.makeKeyAndVisible
|
5
|
+
@window.rootViewController = ConverserViewController.new
|
6
|
+
true
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class ConverserView < UIView
|
2
|
+
attr_reader :conversations_label, :check_button, :read_button
|
3
|
+
|
4
|
+
def init
|
5
|
+
super.tap do
|
6
|
+
self.backgroundColor = UIColor.whiteColor
|
7
|
+
|
8
|
+
@conversations_label = UILabel.new.tap do |label|
|
9
|
+
label.frame = [[57, 79], [207, 54]]
|
10
|
+
label.text = 'No Conversations!'
|
11
|
+
label.textAlignment = NSTextAlignmentCenter
|
12
|
+
end
|
13
|
+
|
14
|
+
@check_button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |button|
|
15
|
+
button.frame = [[116, 204], [89, 44]]
|
16
|
+
button.setTitle('Check', forState: UIControlStateNormal)
|
17
|
+
end
|
18
|
+
|
19
|
+
@read_button = UIButton.buttonWithType(UIButtonTypeRoundedRect).tap do |button|
|
20
|
+
button.frame = [[116, 260], [89, 44]]
|
21
|
+
button.setTitle('Read', forState: UIControlStateNormal)
|
22
|
+
end
|
23
|
+
|
24
|
+
self.addSubview(@conversations_label)
|
25
|
+
self.addSubview(@check_button)
|
26
|
+
self.addSubview(@read_button)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
class ConverserViewController < UIViewController
|
2
|
+
def init
|
3
|
+
super.tap do
|
4
|
+
self.converser = ConverserEngine.instance
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
def loadView
|
9
|
+
self.view = ConverserView.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def viewDidLoad
|
13
|
+
view.check_button.addTarget(
|
14
|
+
self,
|
15
|
+
action: :check_button_tapped,
|
16
|
+
forControlEvents: UIControlEventTouchUpInside
|
17
|
+
)
|
18
|
+
|
19
|
+
view.check_button.addTarget(
|
20
|
+
self,
|
21
|
+
action: :read_button_tapped,
|
22
|
+
forControlEvents: UIControlEventTouchUpInside
|
23
|
+
)
|
24
|
+
|
25
|
+
subscribe_to_converser
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
attr_accessor :converser, :current_conversation
|
31
|
+
|
32
|
+
def check_button_tapped
|
33
|
+
check_for_conversations
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_button_tapped
|
37
|
+
read_conversation
|
38
|
+
end
|
39
|
+
|
40
|
+
def subscribe_to_converser
|
41
|
+
converser.subscribeWithIdentity(
|
42
|
+
'test@example.com',
|
43
|
+
pushToken: nil,
|
44
|
+
completion: lambda do |data|
|
45
|
+
p 'Subscription successful'
|
46
|
+
end,
|
47
|
+
errorHandler: lambda do |error|
|
48
|
+
p 'Subscription error'
|
49
|
+
end
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_for_conversations
|
54
|
+
converser.retrieveInboxWithCompletionBlock(
|
55
|
+
lambda do |inboxItems|
|
56
|
+
if inboxItems.count == 0
|
57
|
+
p 'You have no conversations'
|
58
|
+
else
|
59
|
+
self.current_conversation = inboxItems[0]
|
60
|
+
if current_conversation.status == 'unread'
|
61
|
+
p 'You have a conversation!'
|
62
|
+
else
|
63
|
+
p 'Finished with conversation'
|
64
|
+
finished_with_conversation(current_conversation)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end,
|
68
|
+
errorHandler: lambda do |error|
|
69
|
+
p 'Server not available'
|
70
|
+
end
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
def read_conversation
|
75
|
+
return unless current_conversation
|
76
|
+
|
77
|
+
# Ask the Converser SDK to create a controller that will run the conversation, and display that modally.
|
78
|
+
converserController = converser.viewControllerForConversation(
|
79
|
+
current_conversation.conversationTrackerId,
|
80
|
+
withDelegate: self
|
81
|
+
)
|
82
|
+
|
83
|
+
presentModalViewController(converserController, animated: true)
|
84
|
+
end
|
85
|
+
|
86
|
+
def finished_with_conversation(conversation)
|
87
|
+
if conversation
|
88
|
+
converser.removeInboxItem(
|
89
|
+
conversation.reference,
|
90
|
+
withCompletionBlock: lambda do |data|
|
91
|
+
p 'Successfully finished conversatsion'
|
92
|
+
end,
|
93
|
+
errorHandler: lambda do |error|
|
94
|
+
p 'Failed to finish conversation'
|
95
|
+
end
|
96
|
+
)
|
97
|
+
else
|
98
|
+
p 'Attempt to finish nil conversation'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
Binary file
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-converser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kevin Fagan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Allows RubyMotion projects to easily embed the Converser SDK
|
47
|
+
email:
|
48
|
+
- kevin.fagan1@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/motion-converser.rb
|
59
|
+
- lib/motion/project/converser.rb
|
60
|
+
- motion-converser.gemspec
|
61
|
+
- sample-app/.gitignore
|
62
|
+
- sample-app/Gemfile
|
63
|
+
- sample-app/Rakefile
|
64
|
+
- sample-app/app/app_delegate.rb
|
65
|
+
- sample-app/app/converser_view.rb
|
66
|
+
- sample-app/app/converser_view_controller.rb
|
67
|
+
- sample-app/resources/Default-568h@2x.png
|
68
|
+
- sample-app/spec/main_spec.rb
|
69
|
+
- sample-app/vendor/.gitkeep
|
70
|
+
homepage: https://github.com/kjf/RubyMotion-Converser
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -2712269698344007773
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: -2712269698344007773
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.25
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Converser integration for RubyMotion projects
|
101
|
+
test_files: []
|