daashub_api 0.1.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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83f8bc73250c767dc0b52c289186ec104bf7fa57
4
+ data.tar.gz: bede4240d61519f0657548c5cf9635c98da0f3f9
5
+ SHA512:
6
+ metadata.gz: 988c30319c29318283c35f6fd8e0931ea159a07dbf6c65a44f508ed2651ecd71fd3b7cc52ca53d109a72e107c99d6377bf4fd87a9d354a9e04af26233fd5cbc9
7
+ data.tar.gz: 130a9dc4103c6cd81fc5656760a8e72c7ae89931a286b5100ff0b5ecfaf9bac245a5164ff5a569b5bb5a9706ecf0e689c475649d6fa607d01b413d5bfbe04ef3
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.gem/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /bin/
10
+ /spec/reports/
11
+ /tmp/
12
+ .rbenv-gemsets
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Piotr Brzózka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # DaashubAPI
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/daashub_api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'daashub_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install daashub_api
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/daashub_api.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'daashub_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "daashub_api"
8
+ spec.version = DaashubAPI::VERSION
9
+ spec.authors = ["Piotr Brzózka"]
10
+ spec.email = ["ptbrzozka@gmail.com"]
11
+
12
+ spec.summary = %q{This gem is used to access Daashub API.}
13
+ spec.description = %q{This gem is used to access Daashub API.}
14
+ spec.homepage = "https://github.com/weemanjz/daashub_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "vcr", "~> 3.0"
26
+ spec.add_development_dependency "webmock", "~> 1.22"
27
+ spec.add_dependency "httparty", "~> 0.13"
28
+ end
@@ -0,0 +1,11 @@
1
+ require 'daashub_api/base'
2
+
3
+ module DaashubAPI
4
+ class Account < Base
5
+
6
+ def renewal_date
7
+ (rdate = @attributes[:renewal_date]) && Time.parse(rdate)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module DaashubAPI
2
+ class Base
3
+
4
+ def initialize(args = {})
5
+ @attributes = {}
6
+ args.each { |k, v| @attributes[k.to_sym] = v }
7
+ end
8
+
9
+ protected
10
+
11
+ def method_missing(name, *argv, &block)
12
+ super unless @attributes.key?(name)
13
+ @attributes[name]
14
+ end
15
+
16
+ def respond_to_missing?(name, include_private = false)
17
+ @attributes.key?(name) or super
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ require 'daashub_api/rest/account'
2
+ require 'daashub_api/rest/company'
3
+
4
+ module DaashubAPI
5
+ class Client
6
+ include DaashubAPI::REST::Account
7
+ include DaashubAPI::REST::Company
8
+
9
+ def initialize(access_token)
10
+ @access_token = access_token
11
+ end
12
+
13
+ def access_token
14
+ @access_token
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,38 @@
1
+ module DaashubAPI
2
+ class Company < Base
3
+
4
+ def self.from_array(items)
5
+ @companies = (items['items'] || []).map { |i| new(i) }
6
+ check_for_errors(items)
7
+ add_fields(items['fields'])
8
+ @companies
9
+ end
10
+
11
+ private
12
+
13
+ def self.check_for_errors(items)
14
+ @companies.instance_eval { @daashub_response = items }
15
+ class << @companies
16
+ def error?
17
+ !@daashub_response['errors'].nil?
18
+ end
19
+
20
+ def errors
21
+ @daashub_response['errors'] || []
22
+ end
23
+ end
24
+ end
25
+
26
+ def self.add_fields(fields)
27
+ if fields && fields.kind_of?(Array)
28
+ @companies.instance_eval { @daashub_fields = fields }
29
+ class << @companies
30
+ def daashub_fields
31
+ @daashub_fields
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module DaashubAPI
2
+ class Error < StandardError; end
3
+ class BadRequest < Error; end
4
+ class UnauthorizedError < Error; end
5
+ class PageNotFound < Error; end
6
+ class InternalServerError < Error; end
7
+ end
@@ -0,0 +1,50 @@
1
+ require 'httparty'
2
+ require 'daashub_api/errors'
3
+
4
+ module DaashubAPI
5
+ class Request
6
+ include HTTParty
7
+ base_uri 'https://emailmovers-api.herokuapp.com'
8
+ headers 'Content-Type' => 'application/json'
9
+ format :json
10
+
11
+ class << self
12
+
13
+ def perform_get(endpoint, access_token, options = {})
14
+ headers 'Authorization' => "Token token=#{access_token}"
15
+ response = get(endpoint, options)
16
+ check_for_errors(response)
17
+ response.parsed_response
18
+ end
19
+
20
+ private
21
+
22
+ def check_for_errors(response)
23
+ send("error_#{response.response.code}", response.parsed_response['error']) if response.parsed_response['error']
24
+ end
25
+
26
+ def error_400(message)
27
+ raise BadRequest, message
28
+ end
29
+
30
+ def error_401(message)
31
+ raise UnauthorizedError, message
32
+ end
33
+
34
+ def error_404(message)
35
+ raise PageNotFound, message
36
+ end
37
+
38
+ def error_500(message)
39
+ raise InternalServerError, message
40
+ end
41
+
42
+ def method_missing(name, *args, &block)
43
+ super unless name =~ /^error_/
44
+ raise Error, args.first
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require 'daashub_api/account'
2
+ require 'daashub_api/request'
3
+
4
+ module DaashubAPI
5
+ module REST
6
+ module Account
7
+
8
+ def account_info
9
+ response = DaashubAPI::Request.perform_get('/v1/account/info', access_token)
10
+ DaashubAPI::Account.new(response)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require 'daashub_api/company'
2
+ require 'daashub_api/request'
3
+
4
+ module DaashubAPI
5
+ module REST
6
+ module Company
7
+
8
+ def companies(params = {})
9
+ options = prepare_companies_options(params)
10
+ response = DaashubAPI::Request.perform_get('/v1/companies', access_token, options)
11
+ DaashubAPI::Company.from_array(response)
12
+ end
13
+
14
+ protected
15
+
16
+ def prepare_companies_options(params)
17
+ if params[:where] && params[:where].kind_of?(Hash)
18
+ where = params[:where].first
19
+ params[:where] = "#{where[0]}==#{where[1]}"
20
+ end
21
+ { query: params }
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module DaashubAPI
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ require "daashub_api/client"
2
+ require "daashub_api/version"
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daashub_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Piotr Brzózka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-03 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.22'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.22'
83
+ - !ruby/object:Gem::Dependency
84
+ name: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.13'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.13'
97
+ description: This gem is used to access Daashub API.
98
+ email:
99
+ - ptbrzozka@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - daashub_api.gemspec
112
+ - lib/daashub_api.rb
113
+ - lib/daashub_api/account.rb
114
+ - lib/daashub_api/base.rb
115
+ - lib/daashub_api/client.rb
116
+ - lib/daashub_api/company.rb
117
+ - lib/daashub_api/errors.rb
118
+ - lib/daashub_api/request.rb
119
+ - lib/daashub_api/rest/account.rb
120
+ - lib/daashub_api/rest/company.rb
121
+ - lib/daashub_api/version.rb
122
+ homepage: https://github.com/weemanjz/daashub_api
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.5.1
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: This gem is used to access Daashub API.
146
+ test_files: []