convertloop 0.1.0

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: 8ee72178cce5e08954a47199f437b844e9f1f2f5
4
+ data.tar.gz: 7a956a090d26790ebe9049f6e9834fdfa026b976
5
+ SHA512:
6
+ metadata.gz: 75d6b265a4a70fed0643149401c09804cfa4d99ce17be104a1367d6aebcf93e58464b04f18ea8c257d3c8084af06084c87b87c1b939dcbcef18652d149b51f68
7
+ data.tar.gz: fbbfa38665980592de22d29df7a7f6ff80e07dd227b7774bfd9da98a6a59536669c2e332dbec37bad330bc05906267d593325bf5e907e0de21be223df2c6927f
@@ -0,0 +1,65 @@
1
+ require File.expand_path('person.rb', File.dirname(__FILE__))
2
+ require File.expand_path('event_log.rb', File.dirname(__FILE__))
3
+ require 'net/http'
4
+ require 'net/https'
5
+ require 'json'
6
+
7
+ module ConvertLoop
8
+ class Client
9
+ def initialize(options={})
10
+ @host = options[:host] || "http://api.convertloop.co"
11
+ @version = options[:version] || "v1"
12
+ @app_id = options[:app_id]
13
+ @api_key = options[:api_key]
14
+
15
+ raise ArgumentError, "Missing key ':app_id'" if @app_id.nil? || @app_id.empty?
16
+ raise ArgumentError, "Missing key ':api_key'" if @api_key.nil? || @api_key.empty?
17
+ end
18
+
19
+ def people
20
+ puts "Self: #{self}"
21
+ ConvertLoop::Person.new(self)
22
+ end
23
+
24
+ def event_logs
25
+ ConvertLoop::EventLog.new(self)
26
+ end
27
+
28
+ def post(resource, body)
29
+ uri = URI.parse("#{url}#{resource}")
30
+ http = get_http(uri)
31
+
32
+ request = Net::HTTP::Post.new(uri.path)
33
+ request.basic_auth @app_id, @api_key
34
+ request['Content-Type'] = 'application/json'
35
+ request['Accept'] = 'application/json'
36
+ request['X-API-Source'] = "ruby-#$convertloop_version"
37
+ request.body = body.to_json
38
+
39
+ response = http.request(request)
40
+ parse_json_response(response)
41
+ end
42
+
43
+ def url
44
+ "#{@host}/#{@version}"
45
+ end
46
+
47
+ def get_http(uri)
48
+ http = Net::HTTP.new(uri.host, uri.port)
49
+ if uri.scheme == 'https'
50
+ http.use_ssl = true
51
+ end
52
+
53
+ return http
54
+ end
55
+
56
+ def parse_json_response(response)
57
+ case response
58
+ when Net::HTTPSuccess
59
+ JSON.parse(response.body)
60
+ else
61
+ response.error!
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,15 @@
1
+ module ConvertLoop
2
+ class EventLog
3
+ def initialize(client)
4
+ raise RuntimeError, "No client provided" if client.nil?
5
+ @client = client
6
+ end
7
+
8
+ def send(args={})
9
+ raise ArgumentError, "No args provided" if args.nil?
10
+ raise ArgumentError, "No event name provided" if args[:name].nil? || args[:name].empty?
11
+
12
+ @client.post("/event_logs", args)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ module ConvertLoop
2
+ class Person
3
+ def initialize(client)
4
+ puts "Client: #{client}"
5
+ raise RuntimeError, "No client provided" if client.nil?
6
+ @client = client
7
+ end
8
+
9
+ def create_or_update(args={})
10
+ raise ArgumentError, "No args provided" if args.nil?
11
+ if args[:pid].nil? && args[:user_id] && args[:email]
12
+ raise ArgumentError, "You must supply at least one of the following keys: ':pid' (to update), or ':user_id' and/or ':email' (to create or update)"
13
+ end
14
+
15
+ @client.post("/people", args)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('convertloop/client.rb', File.dirname(__FILE__))
2
+
3
+ # Ruby client of the ConvertLoop API
4
+ module ConvertLoop
5
+
6
+ $convertloop_version = "0.1.0"
7
+
8
+ class << self
9
+ def configure(options={})
10
+ @client = ConvertLoop::Client.new(options)
11
+ end
12
+
13
+ def method_missing(method_name, *args, &block)
14
+ raise RuntimeError, "Please call ConvertLoop.configure(:app_id => '...', :api_key => '...') first" if @client.nil?
15
+ @client.send(method_name, *args, &block)
16
+ end
17
+
18
+ def respond_to_missing?(method_name, include_private=false)
19
+ raise RuntimeError, "Please call ConvertLoop.configure(:app_id => '...', :api_key => '...') first" if @client.nil?
20
+ @client.respond_to?(method_name, include_private)
21
+ end
22
+
23
+ def reset!
24
+ @client = nil
25
+ end
26
+ end
27
+
28
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: convertloop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - German Escobar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-05-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A client of the ConvertLoop API
14
+ email:
15
+ - german.escobarc@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/convertloop.rb
21
+ - lib/convertloop/client.rb
22
+ - lib/convertloop/event_log.rb
23
+ - lib/convertloop/person.rb
24
+ homepage: http://rubygems.org/gems/convertloop
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: ConvertLoop API client
47
+ test_files: []