toolhound-ruby 1.0.4

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: 365f0baac45b1ec5b6b28fbd679cf71d7f405bad
4
+ data.tar.gz: 5b7f413f4130392a675606641f1ee5f45a62ea91
5
+ SHA512:
6
+ metadata.gz: 4ab1bf011348d24008412d59fc7581f912e66a969dcc053512cbee943bd26904a1e47e13521dd82be00d364eefbd7cd135ccfe488b50eb9a30ab4a153ae19e2f
7
+ data.tar.gz: dd830cc1fbd1c5c4ea232843800686891ed4d9f3d536d5e1da58f71c5aaddb7396d67dfca2224ad1eb5b6497ff1f905725032400990dc1c340ecac44fc1cc74a
data/AUTHORS.md ADDED
@@ -0,0 +1,7 @@
1
+ Authors
2
+ =======
3
+
4
+ A huge thanks to all of our contributors:
5
+
6
+
7
+ - This could be you!
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ ruby-nearmiss changelog
2
+ =====================
3
+
4
+ Version 1.0.1
5
+ -------------
6
+
7
+ Release January 4, 2016
8
+
9
+ - Fixed fetching projects
10
+
11
+ Version 1.0.0
12
+ -------------
13
+
14
+ Release January 3, 2016
15
+
16
+ - Intro
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :spec do
6
+ # gem 'jruby-openssl', :platforms => :jruby
7
+ gem 'rake'
8
+ gem 'rspec', '~> 3.3.0'
9
+ gem 'pry'
10
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016, Markus Klooth
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Makefile ADDED
@@ -0,0 +1,15 @@
1
+ install:
2
+ bundle exec rake install
3
+
4
+ test-install:
5
+ bundle install
6
+
7
+ test:
8
+ bundle exec rake spec
9
+
10
+ authors:
11
+ echo "Authors\n=======\n\nA huge thanks to all of our contributors:\n\n" > AUTHORS.md
12
+ git log --raw | grep "^Author: " | cut -d ' ' -f2- | cut -d '<' -f1 | sed 's/^/- /' | sort | uniq >> AUTHORS.md
13
+
14
+ deploy:
15
+ bundle exec rake build | sed -e 's/.*pkg/pkg/g' | sed -e "s/\.$$//g" | xargs gem push
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+
2
+ # nearmiss-ruby
3
+
4
+ A module for using the Nearmiss REST API and generating valid [TwiML](http://www.nearmissapp.com/docs/api/). [Click here to read the full documentation.][documentation]
5
+
6
+ ## Installation
7
+
8
+ To install using [Bundler][bundler] grab the latest stable version:
9
+
10
+ ```ruby
11
+ gem 'nearmiss-ruby', '~> 1.0.0'
12
+ ```
13
+
14
+ To manually install `nearmiss-ruby` via [Rubygems][rubygems] simply gem install:
15
+
16
+ # nearmiss-ruby
17
+
18
+ A module for using the Nearmiss REST API and generating valid [TwiML](http://www.nearmissapp.com/docs/api/). [Click here to read the full documentation.][documentation]
19
+
20
+ ## Installation
21
+
22
+ To install using [Bundler][bundler] grab the latest stable version:
23
+
24
+ ```ruby
25
+ gem 'nearmiss-ruby', '~> 1.0.0'
26
+ ```
27
+
28
+ To manually install `nearmiss-ruby` via [Rubygems][rubygems] simply gem install:
29
+
30
+ ```bash
31
+ gem install nearmiss-ruby
32
+ ```
33
+
34
+ To build and install the development branch yourself from the latest source:
35
+
36
+ ```bash
37
+ git clone git@github.com:nearmiss/nearmiss-ruby.git
38
+ cd nearmiss-ruby
39
+ make install
40
+ ```
41
+
42
+ ## Getting Started With REST
43
+
44
+ ### Setup Work
45
+
46
+ ``` ruby
47
+ require 'rubygems' # not necessary with ruby 1.9 but included for completeness
48
+ require 'nearmiss-ruby'
49
+
50
+ # put your own credentials here
51
+ account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
52
+ auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
53
+
54
+ # set up a client to talk to the Nearmiss REST API
55
+ @client = Nearmiss::REST::Client.new account_sid, auth_token
56
+
57
+ # alternatively, you can preconfigure the client like so
58
+ Nearmiss.configure do |config|
59
+ config.account_sid = account_sid
60
+ config.auth_token = auth_token
61
+ end
62
+
63
+ # and then you can create a new client without parameters
64
+ @client = Nearmiss::REST::Client.new
65
+ ```
66
+
67
+
68
+
69
+ ### List Projects
70
+ You can look up a list of all projects.
71
+
72
+ ``` ruby
73
+ # list calls made or received on or after May 13, 2013
74
+ @client.project_list("start_time>" => "2013-05-13") # Notice we omit the "=" in the "start_time>=" parameter because it is automatically added
75
+ ```
76
+
77
+ ### List Categories
78
+ You can look up a list of all defined categories.
79
+
80
+ ``` ruby
81
+ # list calls made or received on or after May 13, 2013
82
+ @client.categories() # Notice we omit the "=" in the "start_time>=" parameter because it is automatically added
83
+ ```
84
+
85
+
86
+
87
+ ## Supported Ruby Versions
88
+
89
+ This library supports and is [tested against][travis] the following Ruby
90
+ implementations:
91
+
92
+ - Ruby 2.2.0
93
+ - Ruby 2.1.0
94
+ - Ruby 2.0.0
95
+ - Ruby 1.9.3
96
+ - [JRuby][jruby]
97
+ - [Rubinius][rubinius]
98
+
99
+ ## Getting help
100
+
101
+ If you need help installing or using the library, please contact Nearmiss Support at help@nearmiss.com first. Nearmiss's Support staff are well-versed in all of the Nearmiss Helper Libraries, and usually reply within 24 hours.
102
+
103
+ If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
104
+
105
+ ## More Information
106
+
107
+ There are more detailed examples in the included [examples][examples]
108
+ directory. Also for those upgrading, the [upgrade guide][upgrade] is available in the [nearmiss-ruby github wiki][wiki].
109
+
110
+ ```bash
111
+ gem install nearmiss-ruby
112
+ ```
113
+
114
+ To build and install the development branch yourself from the latest source:
115
+
116
+ ```bash
117
+ git clone git@github.com:nearmiss/nearmiss-ruby.git
118
+ cd nearmiss-ruby
119
+ make install
120
+ ```
121
+
122
+ ## Getting Started With REST
123
+
124
+ ### Setup Work
125
+
126
+ ``` ruby
127
+ require 'rubygems' # not necessary with ruby 1.9 but included for completeness
128
+ require 'nearmiss-ruby'
129
+
130
+ # put your own credentials here
131
+ account_sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
132
+ auth_token = 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
133
+
134
+ # set up a client to talk to the Nearmiss REST API
135
+ @client = Nearmiss::REST::Client.new account_sid, auth_token
136
+
137
+ # alternatively, you can preconfigure the client like so
138
+ Nearmiss.configure do |config|
139
+ config.account_sid = account_sid
140
+ config.auth_token = auth_token
141
+ end
142
+
143
+ # and then you can create a new client without parameters
144
+ @client = Nearmiss::REST::Client.new
145
+ ```
146
+
147
+
148
+
149
+ ### List Projects
150
+ You can look up a list of all projects.
151
+
152
+ ``` ruby
153
+ # list calls made or received on or after May 13, 2013
154
+ @client.project_list("start_time>" => "2013-05-13") # Notice we omit the "=" in the "start_time>=" parameter because it is automatically added
155
+ ```
156
+
157
+ ### List Categories
158
+ You can look up a list of all defined categories.
159
+
160
+ ``` ruby
161
+ # list calls made or received on or after May 13, 2013
162
+ @client.categories() # Notice we omit the "=" in the "start_time>=" parameter because it is automatically added
163
+ ```
164
+
165
+
166
+
167
+ ## Supported Ruby Versions
168
+
169
+ This library supports and is [tested against][travis] the following Ruby
170
+ implementations:
171
+
172
+ - Ruby 2.2.0
173
+ - Ruby 2.1.0
174
+ - Ruby 2.0.0
175
+ - Ruby 1.9.3
176
+ - [JRuby][jruby]
177
+ - [Rubinius][rubinius]
178
+
179
+ ## Getting help
180
+
181
+ If you need help installing or using the library, please contact Nearmiss Support at help@nearmiss.com first. Nearmiss's Support staff are well-versed in all of the Nearmiss Helper Libraries, and usually reply within 24 hours.
182
+
183
+ If you've instead found a bug in the library or would like new features added, go ahead and open issues or pull requests against this repo!
184
+
185
+ ## Development
186
+
187
+ If you want to hack on Nearmiss locally, we try to make bootstrapping the project as painless as possible. To start hacking, clone and run:
188
+
189
+ To get started call
190
+ ``` unix
191
+ ./script/bootstrap
192
+ ```
193
+
194
+ To build the gem, call the following from the terminal:
195
+ ``` unix
196
+ ./script/package
197
+ ```
198
+ To push new version to RubyGem and create a git version tag:
199
+ ``` unix
200
+ ./script/release
201
+ ```
202
+
203
+
204
+
205
+ ## More Information
206
+
207
+ There are more detailed examples in the included [examples][examples]
208
+ directory. Also for those upgrading, the [upgrade guide][upgrade] is available in the [nearmiss-ruby github wiki][wiki].
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler.setup
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'rspec/core/rake_task'
6
+ desc 'Run all specs'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+ task test: :spec
@@ -0,0 +1,50 @@
1
+ # require "set"
2
+ # require "faraday"
3
+ # require "sawyer"
4
+ #
5
+ # require "nearmiss-ruby/response"
6
+ # require "nearmiss-ruby/error"
7
+ # require "nearmiss-ruby/raise_error"
8
+ # require "nearmiss-ruby/version"
9
+ require "tiny_tds"
10
+ require "toolhound-ruby/core_ext/string"
11
+ require "toolhound-ruby/configurable"
12
+ # require "nearmiss-ruby/response"
13
+ require "toolhound-ruby/client"
14
+ require "toolhound-ruby/default"
15
+ require "toolhound-ruby/base"
16
+
17
+ require "toolhound-ruby/project"
18
+ # require "nearmiss-ruby/util"
19
+
20
+ module Toolhound
21
+
22
+ class << self
23
+
24
+ include Toolhound::Configurable
25
+ # include Nearmiss::Util
26
+
27
+ # API client based on configured options {Configurable}
28
+ #
29
+ # @return [Toolhound::Client] API wrapper
30
+ def client
31
+ @client = Toolhound::Client.new(options) unless defined?(@client) && @client.same_options?(options)
32
+ @client
33
+ end
34
+
35
+ # @private
36
+ def respond_to_missing?(method_name, include_private=false)
37
+ client.respond_to?(method_name, include_private)
38
+ end
39
+
40
+ private
41
+
42
+ def method_missing(method_name, *args, &block)
43
+ return super unless client.respond_to?(method_name)
44
+ client.send(method_name, *args, &block)
45
+ end
46
+
47
+
48
+ end
49
+ end
50
+ Toolhound.setup
@@ -0,0 +1,64 @@
1
+ module Toolhound
2
+
3
+ # Authentication methods for {Toolhound::Client}
4
+ module Authentication
5
+
6
+ # Indicates if the client was supplied Basic Auth
7
+ # username and password
8
+ #
9
+ # @see
10
+ # @return [Boolean]
11
+ def authenticatable?
12
+ !!(@username && @password && @dataserver)
13
+ end
14
+
15
+ # dataserver: 'pbssrvr\sqlexpress',
16
+ # port: 1433,
17
+ # username: 'mklooth',
18
+ # password: 'ToolHound'
19
+
20
+ def sign_in
21
+ @connection ||= begin
22
+ TinyTds::Client.new(
23
+ dataserver: @dataserver,
24
+ port: @port,
25
+ username: @username,
26
+ password: @password
27
+ )
28
+ end
29
+
30
+ end
31
+
32
+ # def sign_in
33
+ #
34
+ # response = post 'auth/sign_in', { email: @email, password: @password}
35
+ # # update_headers(last_response && last_response.headers)
36
+ # reset_agent
37
+ # @me = response && response[:data] #&& response[:data]
38
+ # end
39
+ # alias :login :sign_in
40
+
41
+ # def update_headers(headers)
42
+ # headers ||= {}
43
+ # # puts "update"
44
+ # # last_response.headers
45
+ # @client_id = headers["client"]
46
+ # @access_token = headers["access-token"]
47
+ # @expiry = headers["expiry"]
48
+ # @uid = headers["uid"]
49
+ # end
50
+
51
+ # Closes the current active session by expiring the ticket.
52
+ #
53
+ def sign_out
54
+ @connection.close if @connection
55
+ @connection = nil
56
+ # post "api/logout"
57
+ # @me = nil
58
+ end
59
+ alias :logout :sign_out
60
+
61
+
62
+ end
63
+
64
+ end
@@ -0,0 +1,94 @@
1
+ module Toolhound
2
+
3
+ class Base
4
+
5
+ attr_accessor :attributes
6
+
7
+ def self.table_name
8
+ @@table_name
9
+ end
10
+
11
+ def self.primary_key
12
+ @@primary_key
13
+ end
14
+
15
+ def self.table_name=(table_name)
16
+ @@table_name = table_name
17
+ end
18
+
19
+ def self.primary_key=(primary_key)
20
+ @@primary_key = primary_key
21
+ end
22
+
23
+
24
+ def self.rename_attributes(hash)
25
+ hash = Hash[hash.map {|key, value| [key.to_s, value] }]
26
+ @@rename_attributes = hash
27
+ end
28
+
29
+ def self.renamed_attributes
30
+ @@rename_attributes ||= {}
31
+ end
32
+
33
+ def self.find(id)
34
+ # table_includes = ""
35
+ results = query "SELECT TOP(1) * FROM #{table_name} #{table_includes} WHERE #{primary_key} = #{id}"
36
+ results.first
37
+ end
38
+
39
+ def self.all(options = {})
40
+ results = query "SELECT * FROM #{table_name}"
41
+
42
+ end
43
+
44
+ def self.query(query)
45
+ klass = self
46
+ results = connection.execute(query)
47
+ results.map do |row|
48
+ klass.new row
49
+ end
50
+ end
51
+
52
+ def self.connection
53
+ @connection ||= Toolhound.connection
54
+ end
55
+
56
+ def initialize(attrs = {}, options = {})
57
+ # @original = attrs
58
+ self.attributes = transform_attributes(attrs)
59
+ end
60
+
61
+ # def attributes=(hash)
62
+ # @attributes = hash
63
+ # end
64
+ #
65
+ # def attributes
66
+ # @attributes
67
+ # end
68
+
69
+
70
+ def transform_attributes(attrs)
71
+ hash = {}
72
+ attrs.each do |k, v|
73
+ key = transform_attribute_key(k)
74
+ hash[key] = v
75
+ end
76
+ hash
77
+ end
78
+
79
+ def transform_attribute_key(key)
80
+ renamed = self.class.renamed_attributes
81
+ if renamed.include? key
82
+ renamed[key].to_sym
83
+ elsif key == self.class.primary_key
84
+ :id
85
+ else
86
+ # "varTransferReceiptPrefix"
87
+ word = key[3..key.length]
88
+ word.underscore.to_sym
89
+ end
90
+ end
91
+
92
+ end
93
+
94
+ end