driftrock-service 0.4.5 → 0.4.6

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.
@@ -17,6 +17,10 @@ module Driftrock::Service::DriftrockModel
17
17
  success
18
18
  end
19
19
 
20
+ def has_profile?
21
+ profile_id && !profile_id.strip.empty?
22
+ end
23
+
20
24
  def update_token(token_data)
21
25
  response = put_to_api_method.call(
22
26
  "/#{channel_type.name}/profile", token_data
@@ -4,6 +4,59 @@ module Driftrock::Service::DriftrockModel
4
4
  set_api_path "/dashboard_api/company"
5
5
 
6
6
  attr_reader :id, :name
7
+
8
+ def channels(refresh=false)
9
+ unless @channels && !refresh
10
+ @channels = []
11
+ response = get_from_api_method.call('/channels')
12
+ response.each do |channel_data|
13
+ channel_data = symbolise_keys(channel_data)
14
+ channel = Channel.new({
15
+ profile_id: channel_data[:profile],
16
+ })
17
+ channel.channel_type = ChannelType.new({
18
+ name: channel_data[:type]
19
+ })
20
+ @channels << channel
21
+ end
22
+ end
23
+ @channels
24
+ end
25
+
26
+ [:facebook, :twitter, :user,
27
+ :adwords, :conversion].each do |channel|
28
+ define_method("has_#{channel}_channel?") do
29
+ channel_type = channel.to_s
30
+ if channel == :adwords
31
+ channel_type = "google_adwords"
32
+ end
33
+ if channel == :conversion
34
+ channel_type = "google_analytics"
35
+ end
36
+ has_channel?(channel_type)
37
+ end
38
+ end
39
+
40
+ def has_channel?(channel_type)
41
+ channel = channel_by_type(channel_type)
42
+ channel && channel.has_profile?
43
+ end
44
+
45
+ def channel_by_type(channel_type)
46
+ channels.find do |channel|
47
+ channel.channel_type.name == channel_type
48
+ end
49
+ end
50
+
51
+
52
+ def has_appropriate_channels_for_app?(app)
53
+ found = [:facebook, :twitter, :user, :adwords, :conversion].find do |channel|
54
+ requires = app.send("requires_#{channel}_data?")
55
+ has = send("has_#{channel}_channel?")
56
+ requires && !has
57
+ end
58
+ !found
59
+ end
7
60
 
8
61
  def add_user(user)
9
62
  response = post_to_api_method.call(
@@ -3,6 +3,20 @@ module Driftrock::Service::DriftrockModel
3
3
  include Driftrock::Service::DriftrockModel
4
4
  set_api_path "/dashboard_api/driftrock_app"
5
5
 
6
+
7
+ [:twitter, :facebook, :adwords, :conversion, :user].each do |data_type|
8
+ define_method("requires_#{data_type}_data?".to_sym) do
9
+ requirement = method("requirement_for_#{data_type}_data").call
10
+ requirement = requirement ? requirement.to_sym : :none
11
+ requirement == :requires
12
+ end
13
+ define_method("uses_#{data_type}_data?".to_sym) do
14
+ requirement = method("requirement_for_#{data_type}_data").call
15
+ requirement = requirement ? requirement.to_sym : :none
16
+ [:requires, :optional].include?(requirement)
17
+ end
18
+ end
19
+
6
20
  def activate
7
21
  post_to_api_method.call("/#{id}/activate")
8
22
  end
@@ -44,7 +58,7 @@ module Driftrock::Service::DriftrockModel
44
58
  end
45
59
  status
46
60
  end
47
-
61
+
48
62
  def self.find_by_app_id(app_id)
49
63
  object_hash = get_from_api_method.call("/#{app_id}/by_app_id")
50
64
  new(object_hash)
@@ -1,5 +1,5 @@
1
1
  module Driftrock
2
2
  module Service
3
- VERSION = "0.4.5"
3
+ VERSION = "0.4.6"
4
4
  end
5
5
  end
@@ -30,4 +30,28 @@ describe DriftrockModel::Company do
30
30
  @test_company.add_user(@test_user).should be_true
31
31
  end
32
32
 
33
+ it "should be have knowledge of which channels it has access to" do
34
+ @get_method.should_receive(:call).with("/channels").and_return([
35
+ {profile: "213213", type: "google_adwords"},
36
+ {profile: "", type: "facebook"}
37
+ ])
38
+ @test_company.has_adwords_channel?.should be_true
39
+ @test_company.has_facebook_channel?.should be_false
40
+ @test_company.has_twitter_channel?.should be_false
41
+ end
42
+
43
+ it "should be able to take an app and identify whether or not they have access" do
44
+ test_app = DriftrockModel::DriftrockApp.new({
45
+ name: "test", requirement_for_facebook_data: "none",
46
+ requirement_for_adwords_data: "requires",
47
+ requirement_for_conversion_data: "requires",
48
+ requirement_for_twitter_data: "none",
49
+ requirement_for_user_data: "optional"
50
+ })
51
+ @get_method.should_receive(:call).with("/channels").and_return([
52
+ {profile: "", type: "google_adwords"}
53
+ ])
54
+ @test_company.has_appropriate_channels_for_app?(test_app).should be_false
55
+ end
56
+
33
57
  end
@@ -13,4 +13,11 @@ describe DriftrockModel::DriftrockApp do
13
13
  DriftrockModel::DriftrockApp.find_by_app_id("string-app-id").id.should == 1
14
14
  end
15
15
 
16
+ it "should allow me to check the requirements of a given app" do
17
+ requires_twitter_only = DriftrockModel::DriftrockApp.new({id: 1, requirement_for_twitter_data: "requires", requirement_for_adwords_data: "none"})
18
+ requires_twitter_only.requires_twitter_data?.should be_true
19
+ requires_twitter_only.uses_adwords_data?.should be_false
20
+ requires_twitter_only.uses_conversion_data?.should be_false
21
+ end
22
+
16
23
  end
metadata CHANGED
@@ -1,55 +1,49 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: driftrock-service
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.5
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.4.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Max
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-06-07 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: httparty
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
17
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
31
27
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
28
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ version_requirements: *id002
46
37
  description: Gem for talking to the driftrock api
47
- email:
38
+ email:
48
39
  - max.dupenois@forward.co.uk
49
40
  executables: []
41
+
50
42
  extensions: []
43
+
51
44
  extra_rdoc_files: []
52
- files:
45
+
46
+ files:
53
47
  - .gitignore
54
48
  - .rspec
55
49
  - Gemfile
@@ -87,29 +81,32 @@ files:
87
81
  - spec/website_spec_helper.rb
88
82
  homepage: https://github.com/forward/driftrock-service
89
83
  licenses: []
84
+
90
85
  post_install_message:
91
86
  rdoc_options: []
92
- require_paths:
87
+
88
+ require_paths:
93
89
  - lib
94
- required_ruby_version: !ruby/object:Gem::Requirement
90
+ required_ruby_version: !ruby/object:Gem::Requirement
95
91
  none: false
96
- requirements:
97
- - - ! '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
100
- required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: "0"
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
97
  none: false
102
- requirements:
103
- - - ! '>='
104
- - !ruby/object:Gem::Version
105
- version: '0'
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: "0"
106
102
  requirements: []
103
+
107
104
  rubyforge_project:
108
105
  rubygems_version: 1.8.24
109
106
  signing_key:
110
107
  specification_version: 3
111
108
  summary: Maintains the api endpoints and the calls to them with authorisation, etc.
112
- test_files:
109
+ test_files:
113
110
  - spec/models/channel_spec.rb
114
111
  - spec/models/channel_type_spec.rb
115
112
  - spec/models/company_spec.rb