streak-ruby 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
+ M2RiZmU2ZGRmNmRhZTNiOTU1NmI0MzY2MjM1M2ZjMWIyYTE1N2NhMg==
5
+ data.tar.gz: !binary |-
6
+ Yzc3MTRmYjlkZjk1YTQyYjFjZTVlY2FlYTY4OWI0MThmYjQxZGUzOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTRkOGIzNDE4MWY5MzE2YzI5MzA4ODY1ZDk4ZDU1NjkxNDBhYzcxZDI1MjUw
10
+ MGEzN2E4YzUxZWE0MTZlODhjOTk3YzliMDNmMzFiMmZlMmQwMjE5MzQ4YzU4
11
+ ODdjYTE5ZDU1MDc1OGI5OTYyOGU4NGJmZWUzMzk5MzFhYjlkM2M=
12
+ data.tar.gz: !binary |-
13
+ YzJhNDE0YjBhZDYwYWY1OGU0ZWQ3YWIxNTUxOTQxZDI1ODZiMGUzOTYwZjQ5
14
+ NmQxMjExOWYxMmNjODE1NmQ5MDRkYmVmYjAxYTBmNzI2NDkzN2FkNjdlNDQy
15
+ MTExYzAyZjY0NGIxMGM1N2I0YTljNTFlZTI4YWZiN2FlNjYzMjE=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in streak.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 JS Boulanger
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,29 @@
1
+ # Streak
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'streak'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install streak
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
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
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
3
+
4
+ libs = " -r irb/completion"
5
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/streak-ruby'}"
6
+ puts "Loading streak-ruby gem"
7
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1 @@
1
+ require 'streak'
data/lib/streak.rb ADDED
@@ -0,0 +1,99 @@
1
+ require 'rest_client'
2
+ require 'multi_json'
3
+
4
+ require "streak/version"
5
+
6
+ require "streak/streak_error"
7
+ require "streak/util"
8
+
9
+ require "streak/streak_object"
10
+ require "streak/box"
11
+ require "streak/field"
12
+ require "streak/field_value"
13
+ require "streak/pipeline"
14
+ require "streak/stage"
15
+ require "streak/user"
16
+
17
+ module Streak
18
+ @api_base = "https://www.streak.com/api/v1"
19
+
20
+ # @ssl_bundle_path = File.dirname(__FILE__) + '/data/ca-certificates.crt'
21
+ # @verify_ssl_certs = true
22
+ #
23
+
24
+ class << self
25
+ attr_accessor :api_key, :api_base, :verify_ssl_certs
26
+ end
27
+
28
+ def self.api_url(url='')
29
+ @api_base + url
30
+ end
31
+
32
+ def self.request(method, url, params = {}, headers = {})
33
+ http_method = method.to_s.downcase.to_sym
34
+ case http_method
35
+ when :get, :head, :delete
36
+ # Make params into GET parameters
37
+ url += "#{URI.parse(url).query ? '&' : '?'}#{uri_encode(params)}" if params && params.any?
38
+ payload = nil
39
+ else
40
+ payload = params.is_a?(String) ? params : uri_encode(params)
41
+
42
+ if http_method == :post
43
+ headers[:content_type] ||= "application/json"
44
+ end
45
+ end
46
+
47
+ request_opts = {
48
+ :headers => headers,
49
+ :method => method,
50
+ :verify_ssl => false,
51
+ :url => api_url(url),
52
+ :user => api_key,
53
+ :payload => payload
54
+ }
55
+
56
+ begin
57
+ response = execute_request(request_opts)
58
+ handle_api_error(response.code, response.body) unless response.code == 200
59
+ rescue RestClient::ExceptionWithResponse => e
60
+ if rcode = e.http_code and rbody = e.http_body
61
+ handle_api_error(rcode, rbody)
62
+ else
63
+ raise
64
+ end
65
+ end
66
+
67
+ parse(response)
68
+ end
69
+
70
+ def self.execute_request(opts)
71
+ RestClient::Request.execute(opts)
72
+ end
73
+
74
+ def self.handle_api_error(rcode, rbody)
75
+ case rcode
76
+ when 400, 404
77
+ raise InvalidRequestError.new("Your request is invalid: #{rbody.inspect}", rcode, rbody)
78
+ when 401
79
+ raise AuthenticationError.new("Your API key is invalid: #{rbody.inspect}", rcode, rbody)
80
+ else
81
+ raise APIError.new("API Error: #{rbody.inspect}", rcode, rbody)
82
+ end
83
+ end
84
+
85
+ def self.parse(response)
86
+ begin
87
+ response = MultiJson.load(response.body)
88
+ rescue MultiJson::DecodeError
89
+ raise APIError.new("Invalid response from the API: #{response.body.inspect}")
90
+ end
91
+ end
92
+
93
+ private
94
+
95
+ def self.uri_encode(params)
96
+ params.map { |k,v| "#{k}=#{URI.escape(v)}" }.join("&")
97
+ end
98
+
99
+ end
data/lib/streak/box.rb ADDED
@@ -0,0 +1,25 @@
1
+ module Streak
2
+ class Box < StreakObject
3
+ def self.all(pipeline_key=nil)
4
+ path = pipeline_key ? "/pipelines/#{pipeline_key}/boxes" : "/boxes"
5
+ res = Streak.request(:get, path)
6
+ convert_to_streak_object(res, Box)
7
+ end
8
+
9
+ def self.find(key)
10
+ res = Streak.request(:get, "/boxes/#{key}")
11
+ convert_to_streak_object(res, Box)
12
+ end
13
+
14
+ def self.create(pipeline_key, params={})
15
+ res = Streak.request(:put, "/pipelines/#{pipeline_key}/boxes", params)
16
+ convert_to_streak_object(res, Box)
17
+ end
18
+
19
+ def self.update(key, params)
20
+ res = Streak.request(:post, "/boxes/#{key}", MultiJson.dump(params))
21
+ convert_to_streak_object(res, Box)
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,24 @@
1
+ module Streak
2
+ class Field < StreakObject
3
+ def self.all(pipeline_key)
4
+ res = Streak.request(:get, "/pipelines/#{pipeline_key}/fields")
5
+ convert_to_streak_object(res, Field)
6
+ end
7
+
8
+ def self.find(pipeline_key, field_key)
9
+ res = Streak.request(:get, "/pipelines/#{pipeline_key}/fields/#{field_key}")
10
+ convert_to_streak_object(res, Field)
11
+ end
12
+
13
+ def self.create(pipeline_key, params)
14
+ res = Streak.request(:put, "/pipelines/#{pipeline_key}/fields", params)
15
+ convert_to_streak_object(res, Field)
16
+ end
17
+
18
+ def self.update(pipeline_key, field_key, params={})
19
+ res = Streak.request(:post, "/pipelines/#{pipeline_key}/fields/#{field_key}", MultiJson.dump(params))
20
+ convert_to_streak_object(res, Field)
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,22 @@
1
+ module Streak
2
+ class FieldValue < StreakObject
3
+ def self.attributes
4
+ [:key, :value]
5
+ end
6
+
7
+ def self.all(box_key)
8
+ res = Streak.request(:get, "/boxes/#{box_key}/fields")
9
+ convert_to_streak_object(res, FieldValue)
10
+ end
11
+
12
+ def self.find(box_key, field_key)
13
+ res = Streak.request(:get, "/boxes/#{box_key}/fields/#{field_key}")
14
+ convert_to_streak_object(res, FieldValue)
15
+ end
16
+
17
+ def self.update(box_key, field_key, params={})
18
+ res = Streak.request(:post, "/boxes/#{box_key}/fields/#{field_key}", MultiJson.dump(params))
19
+ convert_to_streak_object(res, FieldValue)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ module Streak
2
+ class Pipeline < StreakObject
3
+ def self.relations
4
+ { :fields => Streak::Field, :owner => Streak::User, :stages => Streak::Stage }
5
+ end
6
+
7
+ def self.all
8
+ res = Streak.request(:get, "/pipelines")
9
+ convert_to_streak_object(res, Pipeline)
10
+ end
11
+
12
+ def self.find(key)
13
+ res = Streak.request(:get, "/pipelines/#{key}")
14
+ convert_to_streak_object(res, Pipeline)
15
+ end
16
+
17
+ def self.create(params)
18
+ res = Streak.request(:put, "/pipelines", params)
19
+ convert_to_streak_object(res, Pipeline)
20
+ end
21
+
22
+ def self.update(key, params)
23
+ res = Streak.request(:post, "/pipelines/#{key}", MultiJson.dump(params))
24
+ convert_to_streak_object(res, Pipeline)
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,19 @@
1
+ module Streak
2
+ class Stage < StreakObject
3
+ def self.all(pipeline_key)
4
+ res = Streak.request(:get, "/pipelines/#{pipeline_key}/stages")
5
+ convert_to_streak_object(res, Stage)
6
+ end
7
+
8
+ def self.find(pipeline_key, stage_key)
9
+ res = Streak.request(:get, "/pipelines/#{pipeline_key}/stages/#{stage_key}")
10
+ convert_to_streak_object(res, Stage)
11
+ end
12
+
13
+ def self.create(pipeline_key, params)
14
+ res = Streak.request(:put, "/pipelines/#{pipeline_key}/stages", params)
15
+ convert_to_streak_object(res, Stage)
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ module Streak
2
+ class StreakError < StandardError
3
+ def initialize(message=nil, http_status=nil, http_body=nil)
4
+ @message = message
5
+ @http_status = http_status
6
+ @http_body = http_body
7
+ end
8
+
9
+ def to_s
10
+ status_string = @http_status.nil? ? "" : "(Status #{@http_status}) "
11
+ "#{status_string}#{@message}"
12
+ end
13
+ end
14
+
15
+ class InvalidRequestError < StreakError; end
16
+ class AuthenticationError < StreakError; end
17
+ class APIError < StreakError; end
18
+
19
+ end
20
+
@@ -0,0 +1,45 @@
1
+ module Streak
2
+ class StreakObject
3
+
4
+ def self.convert_to_streak_object(resp, type = nil, relation = nil)
5
+ case resp
6
+ when Array
7
+ resp.map { |r| convert_to_streak_object(r, type, relation) }
8
+ when Hash
9
+ object_class = (relation.nil? ? type : type.relations[relation]) || StreakObject
10
+ object_class.construct_from(resp)
11
+ else
12
+ resp
13
+ end
14
+ end
15
+
16
+ def self.attributes
17
+ []
18
+ end
19
+
20
+ def self.relations
21
+ {}
22
+ end
23
+
24
+ def self.construct_from(values)
25
+ object = self.new(values)
26
+ end
27
+
28
+ def initialize(values)
29
+ @values = {}
30
+ (self.class.attributes + values.keys).each do |k|
31
+ attr = Util.symbolize_attribute(k)
32
+ @values[attr] = StreakObject.convert_to_streak_object(values[k], self.class, attr)
33
+ end
34
+ end
35
+
36
+ def method_missing(name, *args)
37
+ if @values.has_key?(name)
38
+ @values[name]
39
+ else
40
+ super
41
+ end
42
+ end
43
+ end
44
+ end
45
+
@@ -0,0 +1,14 @@
1
+ module Streak
2
+ class User < StreakObject
3
+ def self.me
4
+ res = Streak.request(:get, "/users/me")
5
+ convert_to_streak_object(res, User)
6
+ end
7
+
8
+ def self.find(key)
9
+ res = Streak.request(:get, "/users/#{key}")
10
+ convert_to_streak_object(res, User)
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,14 @@
1
+ module Streak
2
+ module Util
3
+ # creatorKey => :creator_key
4
+ def self.symbolize_attribute(attr)
5
+ word = attr.to_s.dup
6
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
7
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
8
+ word.tr!("-", "_")
9
+ word.downcase!
10
+ word.to_sym
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,3 @@
1
+ module Streak
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,167 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'streak'
3
+
4
+ #monkeypatch request methods
5
+ module Streak
6
+ @mock_rest_client = nil
7
+
8
+ def self.mock_rest_client=(mock_client)
9
+ @mock_rest_client = mock_client
10
+ end
11
+
12
+ def self.execute_request(opts)
13
+ get_params = (opts[:headers] || {})[:params]
14
+ post_params = opts[:payload]
15
+ case opts[:method]
16
+ when :get then @mock_rest_client.get opts[:url], get_params, post_params
17
+ when :put then @mock_rest_client.put opts[:url], get_params, post_params
18
+ when :post then @mock_rest_client.post opts[:url], get_params, post_params
19
+ when :delete then @mock_rest_client.delete opts[:url], get_params, post_params
20
+ end
21
+ end
22
+ end
23
+
24
+ def test_response(body, code=200)
25
+ body = MultiJson.dump(body)
26
+ double('Response', :body => body, :code => code)
27
+ end
28
+
29
+ def test_box(params={})
30
+ {
31
+ "pipelineKey" => "agptYWlsZm9vZ2FlcioLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIIV29ya2Zsb3cYPww",
32
+ "creatorKey" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA",
33
+ "creationTimestamp" => 1348260320367,
34
+ "lastUpdatedTimestamp" => 1348342557726,
35
+ "name" => "MySampleBox",
36
+ "stageKey" => "5002",
37
+ "fields" => {
38
+ "1003" => 1347451200000
39
+ },
40
+ "followerKeys" => [
41
+ "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA"
42
+ ],
43
+ "followerCount" => 1,
44
+ "commentCount" => 0,
45
+ "reminderCount" => 0,
46
+ "gmailThreadCount" => 1,
47
+ "fileCount" => 0,
48
+ "boxKey" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEQ2FzZRhaDA",
49
+ "key" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEQ2FzZRhaDA"
50
+ }.merge(params)
51
+ end
52
+
53
+ def test_field(params={})
54
+ {
55
+ "name" => "Assigned To",
56
+ "key" => "1001",
57
+ "type"=> "PERSON"
58
+ }.merge(params)
59
+ end
60
+
61
+ def test_field_value(params={})
62
+ {
63
+ "key" => "1002",
64
+ "value" => "Some string"
65
+ }.merge(params)
66
+ end
67
+
68
+ def test_pipeline(params={})
69
+ {
70
+ "creatorKey" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA",
71
+ "name" => "Hiring",
72
+ "description" => "Use this pipeline to manage hiring potential candidates in your organization. Create a box for each candidate.",
73
+ "orgWide" => false,
74
+ "fields" => [
75
+ {
76
+ "name" => "Assigned To",
77
+ "key" => "1001",
78
+ "type" => "PERSON"
79
+ },
80
+ {
81
+ "name" => "Position",
82
+ "key" => "1002",
83
+ "type" => "TEXT_INPUT"
84
+ },
85
+ {
86
+ "name" => "Start Date",
87
+ "key" => "1003",
88
+ "type" => "DATE"
89
+ }
90
+ ],
91
+ "stages" => {
92
+ "5002" => {
93
+ "name" => "Phone Screen",
94
+ "key" => "5002"
95
+ },
96
+ "5001" => {
97
+ "name" => "Resume",
98
+ "key" => "5001"
99
+ },
100
+ "5004" => {
101
+ "name" => "Internal Decision",
102
+ "key" => "5004"
103
+ },
104
+ "5003" => {
105
+ "name" => "Interview",
106
+ "key" => "5003"
107
+ },
108
+ "5007" => {
109
+ "name" => "Passed",
110
+ "key" => "5007"
111
+ },
112
+ "5005" => {
113
+ "name" => "Offer Negotiation",
114
+ "key" => "5005"
115
+ },
116
+ "5006" => {
117
+ "name" => "Hired",
118
+ "key" => "5006"
119
+ }
120
+ },
121
+ "stageOrder" => [
122
+ "5001",
123
+ "5002",
124
+ "5003",
125
+ "5004",
126
+ "5005",
127
+ "5006",
128
+ "5007"
129
+ ],
130
+ "creationTimestamp" => 1347993556572,
131
+ "lastUpdatedTimestamp" => 1348342589349,
132
+ "aclEntries" => [
133
+ {
134
+ "email" => "aleem@streak.com",
135
+ "isOwner" => false
136
+ }
137
+ ],
138
+ "owner" => {
139
+ "email" => "tesla@streak.com",
140
+ "isOwner" => true
141
+ },
142
+ "pipelineKey" => "agptYWlsZm9vZ2FlcioLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIIV29ya2Zsb3cYMww",
143
+ "key" => "agptYWlsZm9vZ2FlcioLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIIV29ya2Zsb3cYMww"
144
+ }.merge(params)
145
+ end
146
+
147
+ def test_stage(params={})
148
+ {
149
+ "name" => "Interview",
150
+ "key" => "5003"
151
+ }
152
+ end
153
+
154
+ def test_user(params={})
155
+ {
156
+ "email" => "tesla@streak.com",
157
+ "lowercaseEmail" => "tesla@streak.com",
158
+ "creationTimestamp" => 1347660765134,
159
+ "lastUpdatedTimestamp" => 1348463195997,
160
+ "lastSeenTimestamp" => 1348470000000,
161
+ "isOauthComplete" => true,
162
+ "userKey" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA",
163
+ "displayName" => "tesla@streak.com",
164
+ "key" => "agptYWlsZm9vZ2FlciYLEgxPcmdhbml6YXRpb24iCnN0cmVhay5jb20MCxIEVXNlchgBDA"
165
+ }.merge(params)
166
+ end
167
+
@@ -0,0 +1,54 @@
1
+ describe Streak::Box do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:box) { test_box }
4
+
5
+ describe ".all" do
6
+ it "should call the api" do
7
+ api.should_receive(:get).
8
+ with(Streak.api_url("/boxes"), nil, nil).
9
+ and_return(test_response([box]))
10
+
11
+ Streak::Box.all
12
+ end
13
+
14
+ context "for a pipeline" do
15
+ it "should call the api" do
16
+ api.should_receive(:get).
17
+ with(Streak.api_url("/pipelines/pipeline_key_1/boxes"), nil, nil).
18
+ and_return(test_response([box]))
19
+
20
+ Streak::Box.all("pipeline_key_1")
21
+ end
22
+ end
23
+ end
24
+
25
+ describe ".find" do
26
+ it "should call the api" do
27
+ api.should_receive(:get).
28
+ with(Streak.api_url("/boxes/box_key_1"), nil, nil).
29
+ and_return(test_response(box))
30
+
31
+ Streak::Box.find("box_key_1")
32
+ end
33
+ end
34
+
35
+ describe ".create" do
36
+ it "should call the api" do
37
+ api.should_receive(:put).
38
+ with(Streak.api_url("/pipelines/pipeline_key_1/boxes"), nil, "name=Great%20Vendor").
39
+ and_return(test_response(box))
40
+
41
+ Streak::Box.create("pipeline_key_1", :name => "Great Vendor")
42
+ end
43
+ end
44
+
45
+ describe ".update" do
46
+ it "should call the api" do
47
+ api.should_receive(:post).
48
+ with(Streak.api_url("/boxes/box_key_1"), nil, "{\"name\":\"Greatest Vendor\"}").
49
+ and_return(test_response(box))
50
+
51
+ Streak::Box.update("box_key_1", :name => "Greatest Vendor")
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,44 @@
1
+ describe Streak::Field do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:field) { test_field }
4
+
5
+ describe ".all" do
6
+ it "should call the api" do
7
+ api.should_receive(:get).
8
+ with(Streak.api_url("/pipelines/pipeline_key_1/fields"), nil, nil).
9
+ and_return(test_response([field]))
10
+
11
+ Streak::Field.all("pipeline_key_1")
12
+ end
13
+ end
14
+
15
+ describe ".find" do
16
+ it "should call the api" do
17
+ api.should_receive(:get).
18
+ with(Streak.api_url("/pipelines/pipeline_key_1/fields/field_key_1"), nil, nil).
19
+ and_return(test_response(field))
20
+
21
+ Streak::Field.find("pipeline_key_1", "field_key_1")
22
+ end
23
+ end
24
+
25
+ describe ".create" do
26
+ it "should call the api" do
27
+ api.should_receive(:put).
28
+ with(Streak.api_url("/pipelines/pipeline_key_1/fields"), nil, "name=New%20Field").
29
+ and_return(test_response(field))
30
+
31
+ Streak::Field.create("pipeline_key_1", :name => "New Field")
32
+ end
33
+ end
34
+
35
+ describe ".update" do
36
+ it "should call the api" do
37
+ api.should_receive(:post).
38
+ with(Streak.api_url("/pipelines/pipeline_key_1/fields/field_key_1"), nil, "{\"name\":\"New Name\"}").
39
+ and_return(test_response(field))
40
+
41
+ Streak::Field.update("pipeline_key_1", "field_key_1", :name => "New Name")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ describe Streak::FieldValue do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:field_value) { test_field_value }
4
+
5
+ describe ".new" do
6
+ context "when the response has no value" do
7
+ subject { Streak::FieldValue.new(:key => "1002") }
8
+ its(:value) { should be_nil }
9
+ end
10
+ end
11
+
12
+ describe ".all" do
13
+ it "should call the api" do
14
+ api.should_receive(:get).
15
+ with(Streak.api_url("/boxes/box_key_1/fields"), nil, nil).
16
+ and_return(test_response([field_value]))
17
+
18
+ Streak::FieldValue.all("box_key_1")
19
+ end
20
+ end
21
+
22
+ describe ".find" do
23
+ it "should call the api" do
24
+ api.should_receive(:get).
25
+ with(Streak.api_url("/boxes/box_key_1/fields/field_key_1"), nil, nil).
26
+ and_return(test_response(field_value))
27
+
28
+ Streak::FieldValue.find("box_key_1", "field_key_1")
29
+ end
30
+ end
31
+
32
+ describe ".update" do
33
+ it "should call the api" do
34
+ api.should_receive(:post).
35
+ with(Streak.api_url("/boxes/box_key_1/fields/field_key_1"), nil, "{\"value\":\"New value\"}").
36
+ and_return(test_response(field_value))
37
+
38
+ Streak::FieldValue.update("box_key_1", "field_key_1", :value => "New value")
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,44 @@
1
+ describe Streak::Pipeline do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:pipeline) { test_pipeline }
4
+
5
+ describe ".all" do
6
+ it "should call the api" do
7
+ api.should_receive(:get).
8
+ with(Streak.api_url("/pipelines"), nil, nil).
9
+ and_return(test_response([pipeline]))
10
+
11
+ Streak::Pipeline.all
12
+ end
13
+ end
14
+
15
+ describe ".find" do
16
+ it "should call the api" do
17
+ api.should_receive(:get).
18
+ with(Streak.api_url("/pipelines/key_1"), nil, nil).
19
+ and_return(test_response(pipeline))
20
+
21
+ Streak::Pipeline.find("key_1")
22
+ end
23
+ end
24
+
25
+ describe ".create" do
26
+ it "should call the api" do
27
+ api.should_receive(:put).
28
+ with(Streak.api_url("/pipelines"), nil, "name=Sales%20Pipeline").
29
+ and_return(test_response(pipeline))
30
+
31
+ Streak::Pipeline.create(:name => "Sales Pipeline")
32
+ end
33
+ end
34
+
35
+ describe ".update" do
36
+ it "should call the api" do
37
+ api.should_receive(:post).
38
+ with(Streak.api_url("/pipelines/key_1"), nil, "{\"name\":\"Inbound Sales\"}").
39
+ and_return(test_response(pipeline))
40
+
41
+ Streak::Pipeline.update("key_1", :name => "Inbound Sales")
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,34 @@
1
+ describe Streak::Stage do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:stage) { test_stage }
4
+
5
+ describe ".all" do
6
+ it "should call the api" do
7
+ api.should_receive(:get).
8
+ with(Streak.api_url("/pipelines/pipeline_key_1/stages"), nil, nil).
9
+ and_return(test_response([stage]))
10
+
11
+ Streak::Stage.all("pipeline_key_1")
12
+ end
13
+ end
14
+
15
+ describe ".find" do
16
+ it "should call the api" do
17
+ api.should_receive(:get).
18
+ with(Streak.api_url("/pipelines/pipeline_key_1/stages/stage_key_1"), nil, nil).
19
+ and_return(test_response(stage))
20
+
21
+ Streak::Stage.find("pipeline_key_1", "stage_key_1")
22
+ end
23
+ end
24
+
25
+ describe ".create" do
26
+ it "should call the api" do
27
+ api.should_receive(:put).
28
+ with(Streak.api_url("/pipelines/pipeline_key_1/stages"), nil, "name=New%20Stage").
29
+ and_return(test_response(stage))
30
+
31
+ Streak::Stage.create("pipeline_key_1", :name => "New Stage")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,75 @@
1
+ describe Streak::StreakObject do
2
+ describe "#initialize" do
3
+ describe "when creating a new object" do
4
+ # TODO
5
+ end
6
+
7
+ describe "when loading an object from the API" do
8
+ let(:values) { {
9
+ "key" => "5001",
10
+ "creatorKey" => "1234"
11
+ } }
12
+ subject { Streak::StreakObject.new(values) }
13
+
14
+ its(:key) { should == "5001" }
15
+ its(:creator_key) { should == "1234" }
16
+
17
+ context "with a relation type that is defined" do
18
+ before do
19
+ Streak::StreakObject.stub(:relations).and_return({ :owner => Streak::User })
20
+ values["owner"] = { "displayName" => "George" }
21
+ end
22
+
23
+ its(:owner) { should be_instance_of(Streak::User) }
24
+ end
25
+
26
+ context "with a relation type that is undefined" do
27
+ before do
28
+ values["owner"] = { "displayName" => "George" }
29
+ end
30
+
31
+ its(:owner) { should be_instance_of(Streak::StreakObject) }
32
+ end
33
+
34
+ context "with a relation that is an array" do
35
+ before do
36
+ values["fields"] = [{ "name" => "Source" }, { "key" => "1002" }]
37
+ end
38
+
39
+ its(:fields) { should be_instance_of(Array) }
40
+ end
41
+ end
42
+ end
43
+
44
+ describe ".convert_to_streak_object" do
45
+ context "with an Array" do
46
+ let(:response) { [{ "key" => "5001" }, { "key" => "5002" }] }
47
+ subject { Streak::StreakObject.convert_to_streak_object(response) }
48
+ it { should be_instance_of(Array) }
49
+ end
50
+
51
+ context "with a Hash" do
52
+ let(:response) { { "key" => "5001" } }
53
+
54
+ context "when given the target type" do
55
+ subject { Streak::StreakObject.convert_to_streak_object(response, Streak::Pipeline) }
56
+ it { should be_instance_of(Streak::Pipeline) }
57
+ end
58
+
59
+ context "when given the parent's type and relation" do
60
+ subject { Streak::StreakObject.convert_to_streak_object(response, Streak::Pipeline, :fields) }
61
+ it { should be_instance_of(Streak::Field) }
62
+ end
63
+
64
+ context "when target type is not given" do
65
+ subject { Streak::StreakObject.convert_to_streak_object(response) }
66
+ it { should be_instance_of(Streak::StreakObject) }
67
+ end
68
+ end
69
+
70
+ context "with another type" do
71
+ subject { Streak::StreakObject.convert_to_streak_object("value") }
72
+ it { should == "value" }
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,24 @@
1
+ describe Streak::User do
2
+ let!(:api) { Streak.mock_rest_client = double('RestClient') }
3
+ let(:user) { test_user }
4
+
5
+ describe ".me" do
6
+ it "should call the api" do
7
+ api.should_receive(:get).
8
+ with(Streak.api_url("/users/me"), nil, nil).
9
+ and_return(test_response([user]))
10
+
11
+ Streak::User.me
12
+ end
13
+ end
14
+
15
+ describe ".find" do
16
+ it "should call the api" do
17
+ api.should_receive(:get).
18
+ with(Streak.api_url("/users/key_1"), nil, nil).
19
+ and_return(test_response(user))
20
+
21
+ Streak::User.find("key_1")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'streak/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "streak-ruby"
8
+ spec.version = Streak::VERSION
9
+ spec.authors = ["JS Boulanger"]
10
+ spec.email = ["jsboulanger@gmail.com"]
11
+ spec.description = "Ruby bindings for the Streak API."
12
+ spec.summary = "Ruby bindings for the Streak API."
13
+ spec.homepage = "https://github.com/jsboulanger/streak-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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')
22
+ spec.add_dependency('multi_json')
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: streak-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - JS Boulanger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-16 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
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.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ruby bindings for the Streak API.
84
+ email:
85
+ - jsboulanger@gmail.com
86
+ executables:
87
+ - console
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - lib/streak-ruby.rb
99
+ - lib/streak.rb
100
+ - lib/streak/box.rb
101
+ - lib/streak/field.rb
102
+ - lib/streak/field_value.rb
103
+ - lib/streak/pipeline.rb
104
+ - lib/streak/stage.rb
105
+ - lib/streak/streak_error.rb
106
+ - lib/streak/streak_object.rb
107
+ - lib/streak/user.rb
108
+ - lib/streak/util.rb
109
+ - lib/streak/version.rb
110
+ - spec/spec_helper.rb
111
+ - spec/streak/box_spec.rb
112
+ - spec/streak/field_spec.rb
113
+ - spec/streak/field_value_spec.rb
114
+ - spec/streak/pipeline_spec.rb
115
+ - spec/streak/stage_spec.rb
116
+ - spec/streak/streak_object_spec.rb
117
+ - spec/streak/user_spec.rb
118
+ - streak-ruby.gemspec
119
+ homepage: https://github.com/jsboulanger/streak-ruby
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.1.11
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Ruby bindings for the Streak API.
143
+ test_files:
144
+ - spec/spec_helper.rb
145
+ - spec/streak/box_spec.rb
146
+ - spec/streak/field_spec.rb
147
+ - spec/streak/field_value_spec.rb
148
+ - spec/streak/pipeline_spec.rb
149
+ - spec/streak/stage_spec.rb
150
+ - spec/streak/streak_object_spec.rb
151
+ - spec/streak/user_spec.rb