horntell 0.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c1e9a25bd56f75eaff3ecb4006c9f2a19b68b8a1
4
+ data.tar.gz: a7c449eb80509f8f50fd9812f7ef6d964bff6d32
5
+ SHA512:
6
+ metadata.gz: 63f82bca3f8311fee533c4bc7b71d79785023e2bd459b427736d748f109fa78b0b1e7bdb29cef834ba66eb1b6dccc3585413da80a1100480676d14dfb6b92064
7
+ data.tar.gz: 8486ddbb167337758b49e4002185374c75e9ef2f64d840fd0599b550de51473bcc24626de804d5d410c70579fbe6626198af2e581aeca05fc395ac8876f8d463
data/.gitignore ADDED
@@ -0,0 +1,16 @@
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
15
+ .sketches
16
+ /horntell-*.gem
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in horntell-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mohit Mamoria
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,31 @@
1
+ # Horntell::Ruby
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'horntell'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install horntell
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/horntell-ruby/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/horntell.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'horntell/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "horntell"
8
+ spec.version = Horntell::VERSION
9
+ spec.authors = ["Mohit Mamoria"]
10
+ spec.email = ["mohit@horntell.com"]
11
+ spec.summary = "Horntell SDK for Ruby"
12
+ spec.description = ""
13
+ spec.homepage = "http://horntell.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency('rest-client', '~> 1.4')
22
+ spec.add_dependency('json', '~> 1.8.1')
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,17 @@
1
+ module Horntell
2
+ class Campaign
3
+ extend Horntell::Http::Request
4
+
5
+ # triggers campaign for single profile
6
+ def self.to_profile(uid, campaignId)
7
+ return raw_request('post', "/profiles/#{uid}/campaigns/#{campaignId}")
8
+ end
9
+
10
+ #triggers campaign for multiple profile
11
+ def self.to_profiles(profiles, campaignId)
12
+ profiles = { :profile_uids => profiles }
13
+
14
+ return raw_request('post', "/profiles/campaigns/#{campaignId}", profiles)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,4 @@
1
+ module Horntell
2
+ class AuthenticationError < Error
3
+ end
4
+ end
@@ -0,0 +1,13 @@
1
+ module Horntell
2
+ class Error < StandardError
3
+ attr_reader :message
4
+ attr_reader :code
5
+ attr_reader :type
6
+
7
+ def initialize(message = nil, code = nil, type = nil)
8
+ @message = message
9
+ @code = code
10
+ @type = type
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Horntell
2
+ class ForbiddenError < InvalidRequestError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Horntell
2
+ class InvalidRequestError < Error
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module Horntell
2
+ class NetworkError < Error
3
+ attr_accessor :message
4
+ attr_accessor :type
5
+
6
+ def initialize(message = nil, code = nil, type = nil)
7
+ super(message, code, type)
8
+ @message = "Could not connect to Horntell. Please check your network connection and try again. If the problem persists, please get in touch with us at hello@horntell.com."
9
+ @type = 'network_error'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Horntell
2
+ class NotFoundError < InvalidRequestError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Horntell
2
+ class ServiceError < Error
3
+ end
4
+ end
@@ -0,0 +1,17 @@
1
+ module Horntell
2
+ class Horn
3
+ extend Horntell::Http::Request
4
+
5
+ # sends a horn to a profile
6
+ def self.to_profile(uid, horn)
7
+ return raw_request('post', "/profiles/#{uid}/horns", horn)
8
+ end
9
+
10
+ #sends a horn to multiple profiles
11
+ def self.to_profiles(profiles, horn)
12
+ horn[:profile_uids] = profiles
13
+
14
+ return raw_request('post', "/profiles/horns", horn)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,76 @@
1
+ module Horntell
2
+ module Http
3
+ module Client
4
+ def request(method, url, headers=nil, params=nil, username, password)
5
+ begin
6
+ opts = {
7
+ :method => method,
8
+ :headers => headers,
9
+ :url => url,
10
+ :payload => params,
11
+ :user => username,
12
+ :password => password,
13
+ :timeout => 80
14
+ }
15
+
16
+
17
+ response = RestClient::Request.execute(opts)
18
+
19
+ return response
20
+ rescue RestClient::ExceptionWithResponse => e
21
+ if code = e.http_code and body = e.http_body
22
+ return handle_api_error(code, body)
23
+ else
24
+ raise Horntell::NetworkError.new
25
+ end
26
+ rescue Exception => e
27
+ raise Horntell::NetworkError.new
28
+ end
29
+ end
30
+
31
+ def handle_api_error(code, body)
32
+ error_obj = JSON.parse(body)
33
+ error = error_obj["error"]
34
+
35
+ case code
36
+ when 400
37
+ raise invalid_request_error error, code
38
+ when 401
39
+ raise authentication_error error, code
40
+ when 403
41
+ raise forbidden_error error, code
42
+ when 404
43
+ raise not_found_error error, code
44
+ when 500
45
+ raise service_error error, code
46
+ else
47
+ raise error
48
+ end
49
+ end
50
+
51
+ def authentication_error(error, code)
52
+ AuthenticationError.new(error["message"], code, error["type"])
53
+ end
54
+
55
+ def forbidden_error(error, code)
56
+ ForbiddenError.new(error["message"], code, error["type"])
57
+ end
58
+
59
+ def horntell_error(error, code)
60
+ HorntellError.new(error["message"], code, error["type"])
61
+ end
62
+
63
+ def invalid_request_error(error, code)
64
+ InvalidRequestError.new(error["message"], code, error["type"])
65
+ end
66
+
67
+ def not_found_error(error, code)
68
+ NotFoundError.new(error["message"], code, error["type"])
69
+ end
70
+
71
+ def service_error(error, code)
72
+ ServiceError.new(error["message"], code, error["type"])
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,28 @@
1
+ module Horntell
2
+ module Http
3
+ module Request
4
+ include Horntell::Http::Client
5
+ def raw_request(method = nil, endpoint = nil, params = nil)
6
+
7
+ url = Horntell.base+endpoint
8
+
9
+ headers = {
10
+ 'Accept'=> "application/vnd.horntell.#{Horntell::version}+json",
11
+ 'Content-Type' => 'application/json'
12
+ }
13
+
14
+ #parsing data into json
15
+ params = params.to_json
16
+
17
+ response = request(method,
18
+ url,
19
+ headers=headers,
20
+ params=params,
21
+ username=Horntell.key,
22
+ password=Horntell.secret)
23
+ # return response.class
24
+ return Horntell::Http::Response.new(response)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ module Horntell
2
+ module Http
3
+ class Response
4
+ attr_reader :response
5
+ attr_reader :body
6
+ attr_reader :code
7
+
8
+ def initialize(response=nil)
9
+ @response = response
10
+ @body = get_code == 204 ? nil : JSON.parse(response.body)
11
+ end
12
+
13
+ def get_original
14
+ return response
15
+ end
16
+
17
+ def get_body
18
+ return body
19
+ end
20
+
21
+ def get_code
22
+ return response.code
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ module Horntell
2
+ class Profile
3
+ extend Horntell::Http::Request
4
+
5
+ # find profile by its uid
6
+ def self.find(uid)
7
+ return raw_request('get', "/profiles/#{uid}")
8
+ end
9
+
10
+
11
+ def self.create(profile)
12
+ return raw_request('post', "/profiles", profile)
13
+ end
14
+
15
+ # updates a profile by its uid
16
+ def self.update(uid, profile)
17
+ return raw_request('put', "/profiles/#{uid}", profile)
18
+ end
19
+
20
+ # deletes a profile by its uid
21
+ def self.delete(uid)
22
+ return raw_request('delete', "/profiles/#{uid}")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Horntell
2
+ VERSION = "0.1.0"
3
+ end
data/lib/horntell.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ require_relative "horntell/version.rb"
5
+ require_relative 'horntell/errors/error.rb'
6
+ require_relative 'horntell/errors/network_error.rb'
7
+ require_relative 'horntell/errors/invalid_request_error.rb'
8
+ require_relative 'horntell/errors/authentication_error.rb'
9
+ require_relative 'horntell/errors/forbidden_error.rb'
10
+ require_relative 'horntell/errors/not_found_error.rb'
11
+ require_relative 'horntell/errors/service_error.rb'
12
+
13
+ require_relative 'horntell/http/response.rb'
14
+ require_relative 'horntell/http/client.rb'
15
+ require_relative 'horntell/http/request.rb'
16
+
17
+ require_relative 'horntell/profile.rb'
18
+ require_relative 'horntell/horn.rb'
19
+ require_relative 'horntell/campaign.rb'
20
+
21
+ module Horntell
22
+ @base = 'https://api.horntell.com'
23
+ @version = 'v1'
24
+
25
+ class << self
26
+ attr_accessor :key, :secret, :base, :version
27
+
28
+ def init(key = nil, secret = nil)
29
+ @key = key
30
+ @secret = secret
31
+ end
32
+
33
+ def set_base(base=nil)
34
+ @base = base
35
+ end
36
+
37
+ def get_base()
38
+ return @base
39
+ end
40
+
41
+ def get_key()
42
+ return @key
43
+ end
44
+
45
+ def get_secret()
46
+ return @secret
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: horntell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mohit Mamoria
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: ''
70
+ email:
71
+ - mohit@horntell.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - horntell.gemspec
82
+ - lib/horntell.rb
83
+ - lib/horntell/campaign.rb
84
+ - lib/horntell/errors/authentication_error.rb
85
+ - lib/horntell/errors/error.rb
86
+ - lib/horntell/errors/forbidden_error.rb
87
+ - lib/horntell/errors/invalid_request_error.rb
88
+ - lib/horntell/errors/network_error.rb
89
+ - lib/horntell/errors/not_found_error.rb
90
+ - lib/horntell/errors/service_error.rb
91
+ - lib/horntell/horn.rb
92
+ - lib/horntell/http/client.rb
93
+ - lib/horntell/http/request.rb
94
+ - lib/horntell/http/response.rb
95
+ - lib/horntell/profile.rb
96
+ - lib/horntell/version.rb
97
+ homepage: http://horntell.com
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.3
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: Horntell SDK for Ruby
121
+ test_files: []