rappfirst 0.2.0 → 0.3.0

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.
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module Rappfirst
2
4
  class Alert
3
5
 
@@ -6,6 +8,15 @@ module Rappfirst
6
8
 
7
9
  attr_accessor :id
8
10
 
11
+ def writeable_attributes
12
+ # Strip out attributes that are hard to serialize for now, because their API is weird
13
+ ['name', 'active', 'direction', 'interval', 'time_above_threshold', 'threshold']
14
+ end
15
+
16
+ def writeable?(name)
17
+ return writeable_attributes.include?(name)
18
+ end
19
+
9
20
  def initialize(id, api_options=nil, json_data=nil)
10
21
  if api_options && api_options.keys.include?(:basic_auth)
11
22
  username = api_options[:basic_auth][:username]
@@ -18,7 +29,7 @@ module Rappfirst
18
29
  if api_options && api_options.keys.include?(:basic_uri)
19
30
  base_uri = api_options[:base_uri]
20
31
  else
21
- base_uri = 'https://wwws.appfirst.com/api/v3'
32
+ base_uri = 'https://wwws.appfirst.com/api'
22
33
  end
23
34
 
24
35
  self.class.basic_auth username, api_key
@@ -32,8 +43,20 @@ module Rappfirst
32
43
  delete_self
33
44
  end
34
45
 
46
+ def sync
47
+ sync_self
48
+ end
49
+
35
50
  private
36
51
 
52
+ def sync_self
53
+ payload = { :body => attributes_for_put_update }
54
+ response = self.class.put("/alerts/#{self.id}/", payload)
55
+ unless response.success?
56
+ raise "Unable to sync alert #{self.id} with server, received HTTP code #{response.response}"
57
+ end
58
+ end
59
+
37
60
  def delete_self
38
61
  response = self.class.delete("/alerts/#{self.id}/")
39
62
  unless response.code == 200
@@ -41,6 +64,20 @@ module Rappfirst
41
64
  end
42
65
  end
43
66
 
67
+ def attributes_to_hash
68
+ h = Hash.new
69
+ writeable_attributes.each do |a|
70
+ h[a] = self.instance_variable_get('@' + a)
71
+ end
72
+ h
73
+ end
74
+
75
+ def attributes_for_put_update
76
+ attributes_to_hash.map do |k,v|
77
+ "#{k}=#{v}"
78
+ end.join('&')
79
+ end
80
+
44
81
  def set_attributes(json_data=nil)
45
82
  if not json_data
46
83
  response = get_attributes
@@ -10,7 +10,7 @@ module Rappfirst
10
10
  api_key = config['password']
11
11
  end
12
12
  self.class.basic_auth username, api_key
13
- self.class.base_uri 'https://wwws.appfirst.com/api/v3'
13
+ self.class.base_uri 'https://wwws.appfirst.com/api'
14
14
  end
15
15
 
16
16
  def servers(query_string=nil)
@@ -21,7 +21,7 @@ module Rappfirst
21
21
  if api_options && api_options.keys.include?(:basic_uri)
22
22
  base_uri = api_options[:base_uri]
23
23
  else
24
- base_uri = 'https://wwws.appfirst.com/api/v3'
24
+ base_uri = 'https://wwws.appfirst.com/api'
25
25
  end
26
26
 
27
27
  self.class.basic_auth username, api_key
@@ -1,3 +1,3 @@
1
1
  module Rappfirst
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -4,7 +4,7 @@ describe Rappfirst::Alert do
4
4
 
5
5
  describe "default attributes" do
6
6
 
7
- let(:alert) { Rappfirst::Alert.new('114140') }
7
+ let(:alert) { Rappfirst::Alert.new('121038') }
8
8
 
9
9
  before do
10
10
  VCR.insert_cassette 'single_alert', :record => :new_episodes
@@ -19,7 +19,7 @@ describe Rappfirst::Alert do
19
19
  end
20
20
 
21
21
  it "must have the base url set to the Appfirst API" do
22
- alert.class.base_uri.must_equal 'https://wwws.appfirst.com/api/v3'
22
+ alert.class.base_uri.must_equal 'https://wwws.appfirst.com/api'
23
23
  end
24
24
 
25
25
  it "must have API Credentials" do
@@ -32,7 +32,7 @@ describe Rappfirst::Alert do
32
32
 
33
33
  describe "attributes" do
34
34
 
35
- let(:alert) { Rappfirst::Alert.new('114140') }
35
+ let(:alert) { Rappfirst::Alert.new('121038') }
36
36
 
37
37
  before do
38
38
  VCR.insert_cassette 'single_alert', :record => :new_episodes
@@ -44,17 +44,35 @@ describe Rappfirst::Alert do
44
44
 
45
45
  describe "retrieve and create methods" do
46
46
 
47
- it "must populate the target attribute" do
48
- alert.must_respond_to :target
47
+ it "must populate the id attribute" do
48
+ alert.must_respond_to :id
49
+ end
50
+
51
+ it "must make the id attribute unwriteable" do
52
+ n = alert.id
53
+ alert.id = "foobar"
54
+ alert.id.wont_equal "foobar"
55
+ end
56
+
57
+ it "must populate the name attribute" do
58
+ alert.must_respond_to :name
59
+ end
60
+
61
+ it "must make the name attribute writeable" do
62
+ n = alert.name
63
+ alert.name = "foobar"
64
+ alert.name.wont_equal n
49
65
  end
50
66
 
51
67
  end
52
68
 
69
+
70
+
53
71
  end
54
72
 
55
73
  describe "delete alert" do
56
74
 
57
- let(:alert) { Rappfirst::Alert.new('114140') }
75
+ let(:alert) { Rappfirst::Alert.new('121038') }
58
76
 
59
77
  before do
60
78
  VCR.insert_cassette 'single_alert', :record => :new_episodes
@@ -11,7 +11,7 @@ describe Rappfirst::Client do
11
11
  it "must have the base url set to the Appfirst API" do
12
12
  Rappfirst::Client.
13
13
  instance_variable_get("@default_options")[:base_uri].
14
- must_equal 'https://wwws.appfirst.com/api/v3'
14
+ must_equal 'https://wwws.appfirst.com/api'
15
15
  end
16
16
 
17
17
  it "must have API Credentials" do
@@ -19,7 +19,7 @@ describe Rappfirst::Server do
19
19
  end
20
20
 
21
21
  it "must have the base url set to the Appfirst API" do
22
- server.class.base_uri.must_equal 'https://wwws.appfirst.com/api/v3'
22
+ server.class.base_uri.must_equal 'https://wwws.appfirst.com/api'
23
23
  end
24
24
 
25
25
  it "must have API Credentials" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rappfirst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-25 00:00:00.000000000 Z
12
+ date: 2013-07-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  version: '0'
144
144
  segments:
145
145
  - 0
146
- hash: -2428925126903701848
146
+ hash: -2233091851804631922
147
147
  required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  none: false
149
149
  requirements:
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  version: '0'
153
153
  segments:
154
154
  - 0
155
- hash: -2428925126903701848
155
+ hash: -2233091851804631922
156
156
  requirements: []
157
157
  rubyforge_project:
158
158
  rubygems_version: 1.8.23