purple-monkey 0.0.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTMwYmUzZWRkYmNjMGQzMzIxYTM1ZTM4ZmE5NmE4NjhjMTQwMzE4OA==
5
+ data.tar.gz: !binary |-
6
+ YTAxNzUzZGFiZjVlNzBmNDMxZWY0NzUzYWZmNGJiYmEzNzkxOWI4OA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTJmYzViMjE3ZDg1ZDE1ZjkwMTM2ZWE5MDZhM2Y5MzlkMzMxOTBiM2ExYjFj
10
+ ZTFhZjZlYTBmZjk3NDkxMGI3YzViMDQyYzNkOGRmNzI4MjI4MmFjYWRlYjVi
11
+ MWQ1OTlhOTA4MDM0NzJjOWQ0NTM2MGVjOWViMGU4Nzg4NjY1NmE=
12
+ data.tar.gz: !binary |-
13
+ YWU0NDMwMmQ2NDQxYmE1OTdiOTAyZjdjY2VhMTJmNDFiYWJlMWI0OTVmNWQy
14
+ OWUzMGIxY2FjZmExYjNiNDc3YzBlYWRjZTlhNTdjNDg2ZjFjODQwMmY5NjEx
15
+ MjAwYTQ1ZjFiZTUxYzU4YmRiYjM4ODc4MzAwMmJhZTUzMjI1ODY=
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .rake_tasks~
2
+ pkg/*
3
+ build/
4
+ .DS_Store
5
+ .repl_history
6
+ 0
@@ -0,0 +1,9 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ Motion::Project::App.setup do |app|
6
+ Dir.glob(File.join(File.dirname(__FILE__), 'purple-monkey/**/*.rb')).each do |file|
7
+ app.files.unshift(file)
8
+ end
9
+ end
@@ -0,0 +1,82 @@
1
+ # Derived from https://github.com/mailchimp/ChimpKit2/blob/master/Core/Classes/ChimpKit.m
2
+
3
+ # Copyright 2013 Yar Hwee Boon. All rights reserved.
4
+ #
5
+ # All rights reserved.
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions are met:
9
+ #
10
+ # * Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ #
13
+ # * Redistributions in binary form must reproduce the above copyright
14
+ # notice, this list of conditions and the following disclaimer in the
15
+ # documentation and/or other materials provided with the distribution.
16
+ #
17
+ # * Neither the name of MotionObj nor the names of its
18
+ # contributors may be used to endorse or promote products derived from
19
+ # this software without specific prior written permission.
20
+ #
21
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
+ # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
+ # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
+ # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27
+ # TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
+
33
+ class PurpleMonkey
34
+ attr_accessor :api_key
35
+
36
+ def initialize(key)
37
+ self.api_key = key
38
+ end
39
+
40
+
41
+ def call_api_method(method, params:params)
42
+ url = "#{api_url}#{method}"
43
+ data = encode_request_params(params)
44
+
45
+ request = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(url))
46
+ request.setHTTPMethod('POST')
47
+ request.setTimeoutInterval(5)
48
+ request.setHTTPBody(data)
49
+ handler = block_given? ? Proc.new: nil
50
+ NSURLConnection.sendAsynchronousRequest(request, queue:NSOperationQueue.mainQueue, completionHandler:proc {|response, data, error|
51
+ if error.nil?
52
+ #results might be Hash or just true/false
53
+ results = NSJSONSerialization.JSONObjectWithData(data, options:NSJSONReadingMutableContainers|NSJSONReadingAllowFragments, error:nil)
54
+ #p "Response: #{response} #{results}"
55
+ handler.call(results, nil) unless handler.nil?
56
+ else
57
+ #p "Error: #{error}"
58
+ handler.call(nil, error) unless handler.nil?
59
+ end
60
+ })
61
+
62
+ end
63
+
64
+
65
+ def api_url
66
+ "https://#{api_key.split('-')[1]}.api.mailchimp.com/1.3/?method="
67
+ end
68
+
69
+
70
+ def encode_request_params(params)
71
+ post_body_params = {}
72
+ post_body_params['apikey'] = api_key unless api_key.nil?
73
+ post_body_params.merge! params unless params.nil?
74
+ json_encoded = encode_string(NSString.alloc.initWithData(NSJSONSerialization.dataWithJSONObject(post_body_params, options:0, error:nil), encoding:NSUTF8StringEncoding))
75
+ NSMutableData.dataWithData(json_encoded.dataUsingEncoding(NSUTF8StringEncoding))
76
+ end
77
+
78
+
79
+ def encode_string(s)
80
+ CFURLCreateStringByAddingPercentEscapes(nil, s, nil, "!*'();:@&=+$,/?%#[]", KCFStringEncodingUTF8)
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module PurpleMonkey
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/purple-monkey/version.rb', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'purple-monkey'
6
+ gem.version = PurpleMonkey::VERSION
7
+ gem.licenses = ['BSD']
8
+
9
+ gem.authors = ['Hwee-Boon Yar']
10
+
11
+ gem.description = 'Barebones wrapper for working with MailChimp on iOS using RubyMotion'
12
+ gem.summary = 'Barebones wrapper for working with MailChimp on iOS using RubyMotion'
13
+ gem.homepage = 'https://github.com/hboon/purple-monkey'
14
+ gem.email = 'hboon@motionobj.com'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.require_paths = ['lib']
18
+ #gem.test_files = gem.files.grep(%r{^spec/})
19
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: purple-monkey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hwee-Boon Yar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Barebones wrapper for working with MailChimp on iOS using RubyMotion
14
+ email: hboon@motionobj.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - .gitignore
20
+ - lib/purple-monkey.rb
21
+ - lib/purple-monkey/purple-monkey.rb
22
+ - lib/purple-monkey/version.rb
23
+ - purple-monkey.gemspec
24
+ homepage: https://github.com/hboon/purple-monkey
25
+ licenses:
26
+ - BSD
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.0.7
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Barebones wrapper for working with MailChimp on iOS using RubyMotion
48
+ test_files: []