streamsend 0.2.3 → 1.0.0.rc1

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.
Files changed (97) hide show
  1. data/.gitignore +18 -5
  2. data/.rspec +1 -0
  3. data/Gemfile +2 -1
  4. data/Gemfile.lock +25 -17
  5. data/README.md +76 -0
  6. data/Rakefile +1 -2
  7. data/lib/streamsend/api/account.rb +6 -48
  8. data/lib/streamsend/api/audience.rb +14 -0
  9. data/lib/streamsend/api/base/base_call.rb +60 -0
  10. data/lib/streamsend/api/base/create.rb +41 -0
  11. data/lib/streamsend/api/base/destroy.rb +43 -0
  12. data/lib/streamsend/api/base/index.rb +51 -0
  13. data/lib/streamsend/api/base/show.rb +42 -0
  14. data/lib/streamsend/api/base/update.rb +43 -0
  15. data/lib/streamsend/api/blast.rb +51 -0
  16. data/lib/streamsend/api/bounce.rb +20 -0
  17. data/lib/streamsend/api/click.rb +18 -0
  18. data/lib/streamsend/api/configuration.rb +26 -0
  19. data/lib/streamsend/api/email.rb +20 -0
  20. data/lib/streamsend/api/exception.rb +4 -4
  21. data/lib/streamsend/api/field.rb +20 -0
  22. data/lib/streamsend/api/field_option.rb +60 -0
  23. data/lib/streamsend/api/filter.rb +20 -0
  24. data/lib/streamsend/api/from_email_address.rb +24 -0
  25. data/lib/streamsend/api/import.rb +11 -0
  26. data/lib/streamsend/api/link.rb +11 -0
  27. data/lib/streamsend/api/list.rb +13 -39
  28. data/lib/streamsend/api/membership.rb +28 -0
  29. data/lib/streamsend/api/person.rb +66 -0
  30. data/lib/streamsend/api/result.rb +13 -0
  31. data/lib/streamsend/api/session.rb +73 -0
  32. data/lib/streamsend/api/unsubscribe.rb +20 -0
  33. data/lib/streamsend/api/upload.rb +13 -0
  34. data/lib/streamsend/api/user.rb +67 -38
  35. data/lib/streamsend/api/view.rb +8 -0
  36. data/lib/streamsend/version.rb +3 -0
  37. data/lib/streamsend.rb +35 -16
  38. data/spec/lib/streamsend/api/integration/account_spec.rb +50 -0
  39. data/spec/lib/streamsend/api/integration/audience_spec.rb +56 -0
  40. data/spec/lib/streamsend/api/integration/blast_spec.rb +110 -0
  41. data/spec/lib/streamsend/api/integration/bounce_spec.rb +43 -0
  42. data/spec/lib/streamsend/api/integration/click_spec.rb +37 -0
  43. data/spec/lib/streamsend/api/integration/email_spec.rb +76 -0
  44. data/spec/lib/streamsend/api/integration/field_option_spec.rb +87 -0
  45. data/spec/lib/streamsend/api/integration/field_spec.rb +75 -0
  46. data/spec/lib/streamsend/api/integration/filter_spec.rb +101 -0
  47. data/spec/lib/streamsend/api/integration/from_email_address_spec.rb +46 -0
  48. data/spec/lib/streamsend/api/integration/helpers.rb +16 -0
  49. data/spec/lib/streamsend/api/integration/import_spec.rb +35 -0
  50. data/spec/lib/streamsend/api/integration/link_spec.rb +39 -0
  51. data/spec/lib/streamsend/api/integration/list_spec.rb +83 -0
  52. data/spec/lib/streamsend/api/integration/membership_spec.rb +69 -0
  53. data/spec/lib/streamsend/api/integration/person_spec.rb +119 -0
  54. data/spec/lib/streamsend/api/integration/unsubscribe_spec.rb +47 -0
  55. data/spec/lib/streamsend/api/integration/upload_spec.rb +29 -0
  56. data/spec/lib/streamsend/api/integration/user_spec.rb +99 -0
  57. data/spec/lib/streamsend/api/integration/view_spec.rb +27 -0
  58. data/spec/lib/streamsend/api/unit/base/base_call_spec.rb +66 -0
  59. data/spec/lib/streamsend/api/unit/base/create_spec.rb +67 -0
  60. data/spec/lib/streamsend/api/unit/base/destroy_spec.rb +59 -0
  61. data/spec/lib/streamsend/api/unit/base/index_spec.rb +85 -0
  62. data/spec/lib/streamsend/api/unit/base/show_spec.rb +68 -0
  63. data/spec/lib/streamsend/api/unit/base/update_spec.rb +76 -0
  64. data/spec/lib/streamsend/api/unit/blast_spec.rb +79 -0
  65. data/spec/lib/streamsend/api/unit/bounce_spec.rb +36 -0
  66. data/spec/lib/streamsend/api/unit/click_spec.rb +34 -0
  67. data/spec/lib/streamsend/api/unit/field_option_spec.rb +71 -0
  68. data/spec/lib/streamsend/api/unit/from_email_address_spec.rb +20 -0
  69. data/spec/lib/streamsend/api/unit/link_spec.rb +33 -0
  70. data/spec/lib/streamsend/api/unit/list_spec.rb +33 -0
  71. data/spec/lib/streamsend/api/unit/membership_spec.rb +46 -0
  72. data/spec/lib/streamsend/api/unit/person_spec.rb +102 -0
  73. data/spec/lib/streamsend/api/unit/result_spec.rb +13 -0
  74. data/spec/lib/streamsend/api/unit/session_spec.rb +62 -0
  75. data/spec/lib/streamsend/api/unit/unsubscribe_spec.rb +33 -0
  76. data/spec/lib/streamsend/api/unit/user_spec.rb +102 -0
  77. data/spec/spec_helper.rb +8 -11
  78. data/streamsend.gemspec +22 -23
  79. metadata +250 -178
  80. checksums.yaml +0 -7
  81. data/.pair +0 -10
  82. data/README.rdoc +0 -1
  83. data/lib/streamsend/api/resource.rb +0 -41
  84. data/lib/streamsend/api/subscriber.rb +0 -113
  85. data/spec/integration/account_spec.rb +0 -69
  86. data/spec/integration/fixtures/vcr_cassettes/streamsend.yml +0 -6831
  87. data/spec/integration/integration.yml +0 -5
  88. data/spec/integration/list_spec.rb +0 -68
  89. data/spec/integration/spec_helper.rb +0 -16
  90. data/spec/integration/subscriber_spec.rb +0 -24
  91. data/spec/integration/user_spec.rb +0 -58
  92. data/spec/lib/streamsend/api/list_spec.rb +0 -179
  93. data/spec/lib/streamsend/api/resource_spec.rb +0 -24
  94. data/spec/lib/streamsend/api/subscriber_spec.rb +0 -345
  95. data/spec/lib/streamsend/api/user_spec.rb +0 -149
  96. data/spec/lib/streamsend/api_spec.rb +0 -31
  97. data/watcher_config.rb +0 -2
@@ -0,0 +1,20 @@
1
+ module StreamSend
2
+ module Api
3
+ module Email
4
+ class Index < StreamSend::Api::Call::Index
5
+ end
6
+
7
+ class Show < StreamSend::Api::Call::Show
8
+ end
9
+
10
+ class Update < StreamSend::Api::Call::Update
11
+ end
12
+
13
+ class Destroy < StreamSend::Api::Call::Destroy
14
+ end
15
+
16
+ class Create < StreamSend::Api::Call::Create
17
+ end
18
+ end
19
+ end
20
+ end
@@ -6,9 +6,12 @@ module StreamSend
6
6
  class ApiException < Exception
7
7
  end
8
8
 
9
+ class LockedError < ApiException
10
+ end
11
+
9
12
  class SemanticException < ApiException
10
13
  def initialize(other_errors)
11
- @errors = [other_errors].flatten
14
+ @errors = [other_errors].flatten
12
15
  end
13
16
 
14
17
  def errors
@@ -20,9 +23,6 @@ module StreamSend
20
23
  end
21
24
  end
22
25
 
23
- class LockedError < ApiException
24
- end
25
-
26
26
  class UnexpectedResponse < ApiException
27
27
  end
28
28
  end
@@ -0,0 +1,20 @@
1
+ module StreamSend
2
+ module Api
3
+ module Field
4
+ class Index < StreamSend::Api::Call::AudienceIndex
5
+ end
6
+
7
+ class Show < StreamSend::Api::Call::AudienceShow
8
+ end
9
+
10
+ class Update < StreamSend::Api::Call::AudienceUpdate
11
+ end
12
+
13
+ class Create < StreamSend::Api::Call::AudienceCreate
14
+ end
15
+
16
+ class Destroy < StreamSend::Api::Call::AudienceDestroy
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,60 @@
1
+ module StreamSend
2
+ module Api
3
+ module Option
4
+ class Index < StreamSend::Api::Call::Index
5
+ def execute(field_id)
6
+ @field_id = field_id
7
+ super()
8
+ end
9
+
10
+ def uri
11
+ "#{base_audience_only}/fields/#{@field_id}/options.xml"
12
+ end
13
+ end
14
+
15
+ class Show < StreamSend::Api::Call::Show
16
+ def execute(field_id, option_id)
17
+ @field_id = field_id
18
+ super(option_id)
19
+ end
20
+
21
+ def uri
22
+ "#{base_audience_only}/fields/#{@field_id}/options/#{id}.xml"
23
+ end
24
+ end
25
+
26
+ class Update < StreamSend::Api::Call::Update
27
+ def execute(field_id, option_id, object_hash)
28
+ @field_id = field_id
29
+ super(option_id, object_hash)
30
+ end
31
+
32
+ def uri
33
+ "#{base_audience_only}/fields/#{@field_id}/options/#{id}.xml"
34
+ end
35
+ end
36
+
37
+ class Create < StreamSend::Api::Call::Create
38
+ def execute(field_id, object_hash)
39
+ @field_id = field_id
40
+ super(object_hash)
41
+ end
42
+
43
+ def uri
44
+ "#{base_audience_only}/fields/#{@field_id}/options.xml"
45
+ end
46
+ end
47
+
48
+ class Destroy < StreamSend::Api::Call::Destroy
49
+ def execute(field_id, option_id)
50
+ @field_id = field_id
51
+ super(option_id)
52
+ end
53
+
54
+ def uri
55
+ "#{base_audience_only}/fields/#{@field_id}/options/#{id}.xml"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,20 @@
1
+ module StreamSend
2
+ module Api
3
+ module Filter
4
+ class Index < StreamSend::Api::Call::AudienceIndex
5
+ end
6
+
7
+ class Show < StreamSend::Api::Call::AudienceShow
8
+ end
9
+
10
+ class Update < StreamSend::Api::Call::AudienceUpdate
11
+ end
12
+
13
+ class Destroy < StreamSend::Api::Call::AudienceDestroy
14
+ end
15
+
16
+ class Create < StreamSend::Api::Call::AudienceCreate
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module StreamSend
2
+ module Api
3
+ module FromEmailAddress
4
+ class Index < StreamSend::Api::Call::Index
5
+ end
6
+
7
+ class ResendActivationEmail < StreamSend::Api::Call::BaseCall
8
+ def execute(from_email_address_id)
9
+ session.post(uri(from_email_address_id))
10
+ end
11
+
12
+ def uri id
13
+ "#{base_uri}/#{id}/resend_activation_email.xml"
14
+ end
15
+ end
16
+
17
+ class Show < StreamSend::Api::Call::Show
18
+ end
19
+
20
+ class Create < StreamSend::Api::Call::Create
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module StreamSend
2
+ module Api
3
+ module Import
4
+ class Show < StreamSend::Api::Call::AudienceShow
5
+ end
6
+
7
+ class Create < StreamSend::Api::Call::AudienceCreate
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module StreamSend
2
+ module Api
3
+ module Link
4
+ class Index < StreamSend::Api::Call::BlastIndex
5
+ end
6
+
7
+ class Show < StreamSend::Api::Call::BlastShow
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,54 +1,28 @@
1
- require File.expand_path(__FILE__, "exception")
2
-
3
1
  module StreamSend
4
2
  module Api
5
- class List < Resource
6
- def self.all
7
- response = StreamSend::Api.get("/audiences/#{audience_id}/lists.xml")
8
-
9
- case response.code
10
- when 200
11
- response["lists"].collect { |data| new(data) }
12
- else
13
- raise StreamSend::Api::Exception.new("Could not find any lists. (#{response.code})")
3
+ module List
4
+ class Index < StreamSend::Api::Call::AudienceIndex
5
+ def execute(person_id = nil)
6
+ @person_id = person_id
7
+ super()
14
8
  end
15
- end
16
-
17
- def self.find(list_id)
18
- response = StreamSend::Api.get("/audiences/#{audience_id}/lists/#{list_id}.xml")
19
9
 
20
- case response.code
21
- when 200
22
- new(response["list"])
23
- else
24
- raise StreamSend::Api::Exception.new("Could not find any lists. (#{response.code})")
10
+ def uri
11
+ return "#{base_audience_only}/people/#{@person_id}/lists.xml" if @person_id
12
+ audiences_uri
25
13
  end
26
14
  end
27
15
 
28
- def self.create(list_name)
29
- response = StreamSend::Api.post("/audiences/#{audience_id}/lists.xml", :query => {:list => {:name => list_name}})
16
+ class Show < StreamSend::Api::Call::AudienceShow
17
+ end
30
18
 
31
- if response.code == 201
32
- response.headers["location"] =~ /audiences\/\d\/lists\/(\d+)$/
33
- new_list_id = $1.to_i
34
- else
35
- raise StreamSend::Api::Exception.new("Could not create a list. (#{response.body})")
36
- end
19
+ class Update < StreamSend::Api::Call::AudienceUpdate
37
20
  end
38
21
 
39
- def destroy
40
- self.class.destroy( id )
22
+ class Create < StreamSend::Api::Call::AudienceCreate
41
23
  end
42
24
 
43
- def self.destroy( id )
44
- id_as_integer = id.to_i
45
- response = StreamSend::Api.delete("/audiences/#{audience_id}/lists/#{id_as_integer}.xml")
46
- case response.code
47
- when 200
48
- true
49
- else
50
- raise StreamSend::Api::Exception.new "Could not delete list (#{response.code})."
51
- end
25
+ class Destroy < StreamSend::Api::Call::AudienceDestroy
52
26
  end
53
27
  end
54
28
  end
@@ -0,0 +1,28 @@
1
+ module StreamSend
2
+ module Api
3
+ module Membership
4
+ class Index < StreamSend::Api::Call::AudienceIndex
5
+ def execute(person_id, list_id = nil, options = {})
6
+ @person_id = person_id
7
+ @list_id = list_id
8
+ super(options)
9
+ end
10
+
11
+ def uri
12
+ base = "#{base_audience_only}/people/#{@person_id}/"
13
+ return "#{base}lists/#{@list_id}/memberships.xml#{paging_query_string}" if @list_id
14
+ "#{base}memberships.xml#{paging_query_string}"
15
+ end
16
+ end
17
+
18
+ class Show < StreamSend::Api::Call::AudienceShow
19
+ end
20
+
21
+ class Destroy < StreamSend::Api::Call::AudienceDestroy
22
+ end
23
+
24
+ class Create < StreamSend::Api::Call::AudienceCreate
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,66 @@
1
+ module StreamSend
2
+ module Api
3
+ module Person
4
+ class Create < StreamSend::Api::Call::AudienceCreate
5
+ end
6
+
7
+ class Update < StreamSend::Api::Call::AudienceUpdate
8
+ end
9
+
10
+ class Show < StreamSend::Api::Call::AudienceShow
11
+ end
12
+
13
+ class Destroy < StreamSend::Api::Call::AudienceDestroy
14
+ end
15
+
16
+ class Index < StreamSend::Api::Call::AudienceIndex
17
+ def execute(email_address = nil, tracking_hash = nil, options = {})
18
+ @email_address = email_address
19
+ @tracking_hash = tracking_hash
20
+ super(options)
21
+ end
22
+
23
+ def uri
24
+ full_uri = super << paging_query_string
25
+ full_uri << "&email_address=#{@email_address}" if @email_address
26
+ full_uri << "&tracking_hash=#{@tracking_hash}" if @tracking_hash
27
+ full_uri
28
+ end
29
+ end
30
+
31
+ class Activate < StreamSend::Api::Call::BaseCall
32
+ def execute(person_id)
33
+ session.post(uri(person_id))
34
+ end
35
+
36
+ def uri id
37
+ "#{base_audience_uri}/#{id}/activate.xml"
38
+ end
39
+ end
40
+
41
+ class Click < StreamSend::Api::Click::Index
42
+ def uri
43
+ base = "#{session.base_uri}/blasts/#{@blast_id}"
44
+ return "#{base_blast_only_for(@blast_id)}/links/#{@link_id}/clicks/people.xml#{paging_query_string}" if @link_id
45
+ "#{base_blast_only_for(@blast_id)}/clicks/people.xml#{paging_query_string}"
46
+ end
47
+ end
48
+
49
+ class View < StreamSend::Api::Call::BlastIndex
50
+ def uri
51
+ "#{base_blast_only_for(@blast_id)}/views/people.xml#{paging_query_string}"
52
+ end
53
+ end
54
+
55
+ class Unsubscribe < StreamSend::Api::Call::BaseCall
56
+ def execute(person_id)
57
+ session.post(uri(person_id))
58
+ end
59
+
60
+ def uri id
61
+ "#{base_audience_uri}/#{id}/unsubscribe.xml"
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,13 @@
1
+ module StreamSend
2
+ module Api
3
+ class Result < OpenStruct
4
+ def id
5
+ self.marshal_dump[:id].to_i || super
6
+ end
7
+
8
+ def to_hash
9
+ self.marshal_dump
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ module StreamSend
2
+ module Api
3
+ class Session
4
+ def initialize(username = nil, password = nil, base_uri = nil)
5
+ @base_uri = load_base_uri(base_uri)
6
+ @username = load_username(username)
7
+ @password = load_password(password)
8
+ end
9
+
10
+ def load_base_uri base_uri
11
+ return base_uri if base_uri
12
+ return ENV['STREAMSEND_BASE_URI'] if ENV['STREAMSEND_BASE_URI']
13
+ return StreamSend::Api::Configuration.base_uri if StreamSend::Api::Configuration.base_uri
14
+ return "http://app.streamsend.com"
15
+ end
16
+
17
+ def load_username username
18
+ return username if username
19
+ return ENV['STREAMSEND_USERNAME'] if ENV['STREAMSEND_USERNAME']
20
+ return StreamSend::Api::Configuration.username
21
+ raise StreamSend::Api::Exception.new("Unable to create session: no API username provided.")
22
+ end
23
+
24
+ def load_password password
25
+ return password if password
26
+ return ENV['STREAMSEND_PASSWORD'] if ENV['STREAMSEND_PASSWORD']
27
+ return StreamSend::Api::Configuration.password
28
+ raise StreamSend::Api::Exception.new("Unable to create session: no API password provided.")
29
+ end
30
+
31
+ def get(uri, options = {})
32
+ options.merge!(self.basic_auth_credentials)
33
+ HTTParty.get(uri, options)
34
+ end
35
+
36
+ def put(uri, options = {})
37
+ options.merge!(self.basic_auth_credentials)
38
+ HTTParty.put(uri, options)
39
+ end
40
+
41
+ def post(uri, options = {})
42
+ options.merge!(self.basic_auth_credentials)
43
+ HTTMultiParty.post(uri, options)
44
+ end
45
+
46
+ def delete(uri, options = {})
47
+ options.merge!(self.basic_auth_credentials)
48
+ HTTParty.delete(uri, options)
49
+ end
50
+
51
+ def base_uri
52
+ @base_uri
53
+ end
54
+
55
+ def basic_auth_credentials
56
+ { :basic_auth => { :username => @username, :password => @password } }
57
+ end
58
+
59
+ def audience_id
60
+ @audience_id ||= get_audience_id
61
+ end
62
+ private
63
+ def get_audience_id
64
+ audience = StreamSend::Api::Audience::Index.new(self).execute().first
65
+ if audience
66
+ return audience.id
67
+ else
68
+ raise StreamSend::Api::Exception.new("Invalid response when fetching audience. Are your credentials valid?")
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,20 @@
1
+ module StreamSend
2
+ module Api
3
+ module Unsubscribe
4
+ class Index < StreamSend::Api::Call::BlastIndex
5
+ end
6
+
7
+ class Manual < StreamSend::Api::Call::BlastIndex
8
+ def uri
9
+ "#{base_blast_uri_for(@blast_id)}/manual.xml#{paging_query_string}"
10
+ end
11
+ end
12
+
13
+ class Complaint < StreamSend::Api::Call::BlastIndex
14
+ def uri
15
+ "#{base_blast_uri_for(@blast_id)}/complaint.xml#{paging_query_string}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module StreamSend
2
+ module Api
3
+ module Upload
4
+ class Create < StreamSend::Api::Call::Create
5
+ def execute(filepath)
6
+ upload_hash = nil
7
+ options = { :query => { :data => File.new(filepath) } }
8
+ super(upload_hash, options)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,54 +1,83 @@
1
- require "active_support/core_ext/hash"
2
- require File.expand_path(__FILE__, "exception")
3
-
4
1
  module StreamSend
5
2
  module Api
6
- class User < Resource
7
- def self.all
8
- response = StreamSend::Api.get("/users.xml")
3
+ module User
4
+ class Index < StreamSend::Api::Call::Index
5
+ def execute(account_id = nil)
6
+ @account_id = account_id
7
+ super()
8
+ end
9
+
10
+ def uri
11
+ return users_uri(@account_id) if @account_id
12
+ super
13
+ end
14
+ end
15
+
16
+ class Show < StreamSend::Api::Call::Show
17
+ def execute(user_id, account_id = nil)
18
+ @account_id = account_id
19
+ super(user_id)
20
+ end
21
+
22
+ def uri
23
+ return user_uri_for(@account_id, id) if @account_id
24
+ super
25
+ end
26
+ end
27
+
28
+ class Destroy < StreamSend::Api::Call::Destroy
29
+ def execute(user_id, account_id = nil)
30
+ @account_id = account_id
31
+ super(user_id)
32
+ end
9
33
 
10
- case response.code
11
- when 200
12
- response["users"].collect { |data| new(data) }
13
- else
14
- raise StreamSend::Api::Exception.new("Could not find any users. Make sure your account ID is correct. (#{response.code})")
34
+ def uri
35
+ return user_uri_for(@account_id, id) if @account_id
36
+ super
15
37
  end
16
38
  end
17
39
 
18
- def self.show(id)
19
- response = StreamSend::Api.get("/users/#{id}.xml")
20
- case response.code
21
- when 200
22
- new(response["user"])
23
- else
24
- raise StreamSend::Api::Exception.new("Could not find the user. Make sure your account ID and user ID are correct. (#{response.code})")
40
+ class Create < StreamSend::Api::Call::Create
41
+ def execute(user_hash, account_id = nil)
42
+ @account_id = account_id
43
+ super(user_hash)
44
+ end
45
+
46
+ def uri
47
+ return users_uri(@account_id) if @account_id
48
+ super
25
49
  end
26
50
  end
27
51
 
28
- def self.update(user_hash)
29
- user_properties = user_hash.clone
30
- user_properties.delete 'user_id'
31
- user_properties.delete 'account_id'
52
+ class Update < StreamSend::Api::Call::Update
53
+ def execute(user_id, user_hash, account_id = nil)
54
+ @account_id = account_id
55
+ super(user_id, user_hash)
56
+ end
32
57
 
33
- xml_hash = user_properties.to_xml :root => "user"
34
- response = StreamSend::Api.put("/accounts/#{user_hash['account_id']}/users/#{user_hash['user_id']}.xml", :body => xml_hash, :headers => {'Content-Type' => 'application/xml', 'Accept' => 'application/xml'})
35
- case response.code
36
- when 200
37
- true
38
- else
39
- false
58
+ def uri
59
+ return user_uri_for(@account_id, id) if @account_id
60
+ super
40
61
  end
41
62
  end
42
63
 
43
- def self.create(user_hash)
44
- response = StreamSend::Api.post("/accounts/#{user_hash['account_id']}/users.xml", :body => {:user => user_hash})
45
- case response.code
46
- when 201
47
- response.headers["location"] =~ /\/accounts\/\d+\/users\/(\d+)/
48
- user_id = $1
49
- user_id.to_i
50
- else
51
- raise StreamSend::Api::Exception.new("Could not create the user. (#{response.code})")
64
+ class Login < StreamSend::Api::Call::BaseCall
65
+ def execute(user_id, account_id = nil)
66
+ @user_id = user_id
67
+ @account_id = account_id
68
+ response = session.post(uri, :follow_redirects => false)
69
+
70
+ case response.code
71
+ when 302
72
+ response.headers["location"].split("/").last
73
+ else
74
+ raise StreamSend::Api::Exception.new("Could not log the user in.")
75
+ end
76
+ end
77
+
78
+ def uri
79
+ return "#{session.base_uri}/accounts/#{@account_id}/users/#{@user_id}/login.xml" if @account_id
80
+ "#{session.base_uri}/users/#{@user_id}/login.xml"
52
81
  end
53
82
  end
54
83
  end
@@ -0,0 +1,8 @@
1
+ module StreamSend
2
+ module Api
3
+ module View
4
+ class Index < StreamSend::Api::Call::BlastIndex
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module StreamSend
2
+ VERSION = "1.0.0.rc1"
3
+ end
data/lib/streamsend.rb CHANGED
@@ -1,22 +1,41 @@
1
- require 'rubygems'
2
- require 'httparty'
1
+ require "rubygems"
2
+ require "httmultiparty"
3
+ require "ostruct"
4
+ require "active_support/inflector"
5
+ require "active_support/core_ext"
3
6
 
4
- require "streamsend/api/resource"
5
- require "streamsend/api/subscriber"
7
+ require "streamsend/version"
8
+ require "streamsend/api/configuration"
9
+ require "streamsend/api/result"
10
+ require "streamsend/api/exception"
11
+ require "streamsend/api/base/base_call"
12
+ require "streamsend/api/base/index"
13
+ require "streamsend/api/base/show"
14
+ require "streamsend/api/base/update"
15
+ require "streamsend/api/base/create"
16
+ require "streamsend/api/base/destroy"
17
+ require "streamsend/api/audience"
18
+ require "streamsend/api/session"
19
+
20
+ require "streamsend/api/account"
21
+ require "streamsend/api/blast"
22
+ require "streamsend/api/bounce"
23
+ require "streamsend/api/click"
24
+ require "streamsend/api/email"
25
+ require "streamsend/api/field"
26
+ require "streamsend/api/field_option"
27
+ require "streamsend/api/filter"
28
+ require "streamsend/api/from_email_address"
29
+ require "streamsend/api/link"
6
30
  require "streamsend/api/list"
31
+ require "streamsend/api/import"
32
+ require "streamsend/api/membership"
33
+ require "streamsend/api/person"
34
+ require "streamsend/api/unsubscribe"
35
+ require "streamsend/api/upload"
36
+ require "streamsend/api/view"
7
37
  require "streamsend/api/user"
8
- require "streamsend/api/account"
9
- require "streamsend/api/exception"
10
38
 
11
39
  module StreamSend
12
- module Api
13
- include HTTParty
14
- format :xml
15
-
16
- def self.configure(username, password, host = "app.streamsend.com")
17
- base_uri host
18
- basic_auth username, password
19
- StreamSend::Api::Subscriber.clear_audience
20
- end
21
- end
40
+ PER_PAGE_DEFAULT = 100
22
41
  end