streaker 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bc2a4a60a0faa7cc2b4a9d4c9dd926a5bbed55f
4
- data.tar.gz: 666da415df2bf8e6111dad1af75cc1a78239d477
3
+ metadata.gz: 9e20542e5dc258218ae5ed0778b4c415669b0f66
4
+ data.tar.gz: 6687c299e86cc61b48c9dd52c8270829dac2bfe4
5
5
  SHA512:
6
- metadata.gz: 384896b543a2460b39c15fadef23d5144bc29c5a3c57e15cb60710296f5235c96bc6395fb91c1ac093e4144a93500fd016d05ea3574542b16023e949decbf0e6
7
- data.tar.gz: 8dd14b39543a428545249b893d268aef075937ac6ffd84486f685fce60d2473d72f1fd24e50eaccf28f4c92fedda9cf9e04a1cbdde8c6d126ced205f6d8abd4c
6
+ metadata.gz: 93ede4c70c91e869c14b212ac50344d6194511e4d5eb06b8e49458efe6ca8c7ec4cd12adf67e8e51029a8479383ab54d9b5f3e53d7adef87976797217e4b2fd4
7
+ data.tar.gz: 8432974d66b3cc9a70269ee69a04bed26f612f6b9eb8b66cda65e1b5177399228cfb97a1d3cf56783aca6e8f152eedd3b122f283bed3f27a819b986b45d9d3a8
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [1.1.0] - 2018-08-21
6
+
7
+ Features:
8
+ - Replace `streak-ruby` dependency by `http`.
9
+ - Make only one call to update a box instead of one per attribute.
10
+ - Create a box with persons assigned.
11
+
5
12
  ## [1.0.0] - 2017-12-11
6
13
 
7
14
  First release! :tada:
data/README.md CHANGED
@@ -33,6 +33,7 @@ box = Streaker::Box.create(
33
33
  name: 'Some box name',
34
34
  stage: :my_stage,
35
35
  my_field: 'Some field value',
36
+ assigned_to: ['streak-owner@email.com', 'streak-contributor@email.com', …]
36
37
 
37
38
  )
38
39
  box.key # => your new box's key
@@ -43,11 +44,13 @@ Update a box:
43
44
  ```rb
44
45
  box = Streaker::Box.new('a_box_key')
45
46
  box.update(
47
+ name: 'my box name',
48
+ stage: :some_other_stage,
46
49
  my_field: 'A new field value',
47
-
48
50
  )
49
51
  ```
50
52
 
53
+
51
54
  ## Configuration
52
55
 
53
56
  Configure Streaker:
@@ -60,6 +63,7 @@ Streaker.configure do |config|
60
63
  # Provide an identifier for the pipeline(s) you want to access.
61
64
  # You can find the pipeline keys keys by configuring your api key, then typing
62
65
  # inside a console:
66
+ #
63
67
  # > Streak::Pipeline.all.map { |p| [p.key, p.name] }.to_h
64
68
  config.pipeline_keys = {
65
69
  default: 'YOUR_PIPELINE_KEY_HERE',
@@ -82,7 +86,6 @@ Streaker.configure do |config|
82
86
  # You can find all the field keys by configuring a pipeline key, then typing
83
87
  # inside a console:
84
88
  #
85
- # $ bin/console
86
89
  # > pipeline_key = Streaker.configuration.pipeline_keys.values.first
87
90
  # > box = Streak::Box.all(pipeline_key).first ; nil
88
91
  # > Streak::FieldValue.all(box.key)
@@ -0,0 +1,82 @@
1
+ module Streaker
2
+ # Allow the streaker gem to execute http calls to the streak api
3
+ class API
4
+ STREAK_URL = 'https://www.streak.com'.freeze
5
+
6
+ def initialize(api_key: nil)
7
+ @api_key = api_key || Streaker.configuration.api_key
8
+ end
9
+
10
+ def update_box(key, attributes)
11
+ response = client.post(
12
+ "#{STREAK_URL}/api/v1/boxes/#{key}",
13
+ json: update_box_params(attributes)
14
+ )
15
+
16
+ JSON.parse(response.body.to_s)
17
+ end
18
+
19
+ def create_box(pipeline_key, name:, assigned_to: [])
20
+ response = client.put(
21
+ "#{STREAK_URL}/api/v1/pipelines/#{pipeline_key}/boxes",
22
+ form: create_box_params(name: name, assigned_to: assigned_to)
23
+ )
24
+
25
+ JSON.parse(response.body.to_s)
26
+ end
27
+
28
+ def find_box(box_key)
29
+ response = client.get(
30
+ "#{STREAK_URL}/api/v1/boxes/#{box_key}"
31
+ )
32
+
33
+ JSON.parse(response.body.to_s)
34
+ end
35
+
36
+ private_constant :STREAK_URL
37
+
38
+ private
39
+
40
+ attr_reader :api_key
41
+
42
+ def update_box_params(attributes)
43
+ {
44
+ name: attributes.delete(:name),
45
+ stageKey: find_streak_stage_key_key(attributes.delete(:stage)),
46
+ fields: format_fields_for_streak(attributes)
47
+ }.delete_if { |_k, v| v.nil? }
48
+ end
49
+
50
+ def create_box_params(name:, assigned_to: [])
51
+ return { name: name } unless assigned_to.any?
52
+
53
+ {
54
+ name: name,
55
+ assignedToSharingEntries: format_emails(assigned_to).to_json
56
+ }
57
+ end
58
+
59
+ def format_emails(array)
60
+ array.map do |email|
61
+ {
62
+ email: email
63
+ }
64
+ end
65
+ end
66
+
67
+ def format_fields_for_streak(attributes)
68
+ attributes.map { |k, v| [Streaker.configuration.field_keys[k], v] }.to_h
69
+ end
70
+
71
+ def find_streak_stage_key_key(key)
72
+ Streaker.configuration.stage_keys[key]
73
+ end
74
+
75
+ def client
76
+ @client ||= HTTP.headers(accept: 'application/json').basic_auth(
77
+ user: api_key,
78
+ pass: ''
79
+ )
80
+ end
81
+ end
82
+ end
data/lib/streaker/box.rb CHANGED
@@ -22,10 +22,9 @@ module Streaker
22
22
  # You can also give a `stage: :stage` or
23
23
  def update(attributes)
24
24
  verify_if_box_exists
25
+ api_result = api.update_box(key, attributes)
25
26
 
26
- attributes.each do |attr, value|
27
- update_attribute(attr, value)
28
- end
27
+ raise Streaker::Box::Error, api_result['error'] if api_result['error']
29
28
 
30
29
  true
31
30
  end
@@ -38,11 +37,19 @@ module Streaker
38
37
  # some_field_key: 'Some field value',
39
38
  # …
40
39
  # )
41
- def self.create(name:, pipeline: :default, **attributes)
42
- api_result = Streak::Box.create(pipeline_key(pipeline), name: name)
43
- box = new(api_result.key)
44
- box.update(attributes)
45
- box
40
+ def self.create(name:, pipeline: :default, assigned_to: [], **attributes)
41
+ api = Streaker::API.new
42
+ api_result = api.create_box(
43
+ pipeline_key(pipeline),
44
+ name: name,
45
+ assigned_to: assigned_to
46
+ )
47
+
48
+ raise Streaker::Box::Error, api_result['error'] if api_result['error']
49
+
50
+ api.update_box(api_result['key'], name: name, **attributes)
51
+
52
+ new(api_result['key'])
46
53
  end
47
54
 
48
55
  def self.pipeline_key(pipeline)
@@ -57,13 +64,15 @@ module Streaker
57
64
  private
58
65
 
59
66
  def verify_if_box_exists
60
- Streak::Box.find(key)
61
- rescue Streak::InvalidRequestError => e
62
- if /Entity not found with key/ =~ e.message
63
- raise Streaker::BoxNotFoundError, "Entity not found with key #{key}"
64
- else
65
- raise e
67
+ result = api.find_box(key)
68
+
69
+ return unless result['error']
70
+
71
+ if /Entity not found with key/ =~ result['error']
72
+ raise Streaker::BoxNotFoundError, result['error']
66
73
  end
74
+
75
+ raise Streaker::Box::Error, result['error']
67
76
  end
68
77
 
69
78
  def stage_key(stage)
@@ -80,15 +89,8 @@ module Streaker
80
89
  "No such field #{field.inspect} in the configuration"
81
90
  end
82
91
 
83
- def update_attribute(attr, value)
84
- case attr
85
- when :stage
86
- Streak::Box.update(key, stageKey: stage_key(value))
87
- when :name
88
- Streak::Box.update(key, name: value)
89
- else
90
- Streak::FieldValue.update(key, field_key(attr), value: value)
91
- end
92
+ def api
93
+ Streaker::API.new
92
94
  end
93
95
  end
94
96
  end
@@ -2,10 +2,10 @@
2
2
  module Streaker
3
3
  # The configuration singleton.
4
4
  class Configuration
5
- attr_reader :api_key
6
5
  attr_accessor :pipeline_keys,
7
6
  :stage_keys,
8
- :field_keys
7
+ :field_keys,
8
+ :api_key
9
9
 
10
10
  def initialize
11
11
  @api_key = ''
@@ -13,12 +13,6 @@ module Streaker
13
13
  @stage_keys = {}
14
14
  @field_keys = {}
15
15
  end
16
-
17
- def api_key=(value)
18
- @api_key = value
19
-
20
- Streak.api_key = value
21
- end
22
16
  end
23
17
 
24
18
  # Configuration setup
@@ -1,3 +1,3 @@
1
1
  module Streaker
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
data/lib/streaker.rb CHANGED
@@ -1,6 +1,7 @@
1
- require 'streak-ruby'
1
+ require 'http'
2
2
 
3
3
  require 'streaker/version'
4
4
  require 'streaker/configuration'
5
+ require 'streaker/api'
5
6
  require 'streaker/box'
6
7
  require 'streaker/box_not_found_error'
data/streaker.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Sunny Ripert', 'William Pollet']
10
10
  spec.email = %w[
11
11
  sunny.ripert@kisskissbankbank.com
12
- william.pollet@KissKissBankBank.com
12
+ william.pollet@kisskissbankbank.com
13
13
  ]
14
14
 
15
15
  spec.summary = 'Access the Streak API'
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
21
21
  end
22
22
  spec.require_paths = ['lib']
23
23
 
24
- # API Bindings to Streak
25
- spec.add_dependency 'streak-ruby', '>= 0.0.2', '< 1'
24
+ # API calls
25
+ spec.add_development_dependency 'http', '~> 3.3.0'
26
26
 
27
27
  # Record HTTP Interactions
28
28
  spec.add_development_dependency 'vcr', '~> 3.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: streaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunny Ripert
@@ -9,28 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-11 00:00:00.000000000 Z
12
+ date: 2018-08-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: streak-ruby
15
+ name: http
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: 0.0.2
21
- - - "<"
18
+ - - "~>"
22
19
  - !ruby/object:Gem::Version
23
- version: '1'
24
- type: :runtime
20
+ version: 3.3.0
21
+ type: :development
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: 0.0.2
31
- - - "<"
25
+ - - "~>"
32
26
  - !ruby/object:Gem::Version
33
- version: '1'
27
+ version: 3.3.0
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: vcr
36
30
  requirement: !ruby/object:Gem::Requirement
@@ -132,7 +126,7 @@ dependencies:
132
126
  description: Access the Streak API thanks to the streak-ruby gem
133
127
  email:
134
128
  - sunny.ripert@kisskissbankbank.com
135
- - william.pollet@KissKissBankBank.com
129
+ - william.pollet@kisskissbankbank.com
136
130
  executables: []
137
131
  extensions: []
138
132
  extra_rdoc_files: []
@@ -150,6 +144,7 @@ files:
150
144
  - bin/console
151
145
  - bin/setup
152
146
  - lib/streaker.rb
147
+ - lib/streaker/api.rb
153
148
  - lib/streaker/box.rb
154
149
  - lib/streaker/box_not_found_error.rb
155
150
  - lib/streaker/configuration.rb
@@ -174,9 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
169
  version: '0'
175
170
  requirements: []
176
171
  rubyforge_project:
177
- rubygems_version: 2.5.2
172
+ rubygems_version: 2.5.2.3
178
173
  signing_key:
179
174
  specification_version: 4
180
175
  summary: Access the Streak API
181
176
  test_files: []
182
- has_rdoc: