mailjet 0.0.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +81 -259
  3. data/Rakefile +5 -4
  4. data/lib/mailjet.rb +7 -11
  5. data/lib/mailjet/api_error.rb +9 -5
  6. data/lib/mailjet/collection_proxy.rb +15 -0
  7. data/lib/mailjet/configuration.rb +4 -8
  8. data/lib/mailjet/connection.rb +72 -0
  9. data/lib/mailjet/gem_extensions/rest_client.rb +19 -0
  10. data/lib/mailjet/mailer.rb +37 -2
  11. data/lib/mailjet/message_delivery.rb +9 -0
  12. data/lib/mailjet/reporting.rb +10 -7
  13. data/lib/mailjet/resource.rb +199 -0
  14. data/lib/mailjet/resources/apikey.rb +12 -0
  15. data/lib/mailjet/resources/apikeyaccess.rb +12 -0
  16. data/lib/mailjet/resources/apikeytotals.rb +14 -0
  17. data/lib/mailjet/resources/apitoken.rb +12 -0
  18. data/lib/mailjet/resources/batchjob.rb +12 -0
  19. data/lib/mailjet/resources/bouncestatistics.rb +14 -0
  20. data/lib/mailjet/resources/campaign.rb +12 -0
  21. data/lib/mailjet/resources/campaignstatistics.rb +14 -0
  22. data/lib/mailjet/resources/clickstatistics.rb +14 -0
  23. data/lib/mailjet/resources/contact.rb +12 -0
  24. data/lib/mailjet/resources/contactdata.rb +12 -0
  25. data/lib/mailjet/resources/contactfilter.rb +12 -0
  26. data/lib/mailjet/resources/contacthistorydata.rb +12 -0
  27. data/lib/mailjet/resources/contactmetadata.rb +12 -0
  28. data/lib/mailjet/resources/contactslist.rb +12 -0
  29. data/lib/mailjet/resources/contactslistsignup.rb +12 -0
  30. data/lib/mailjet/resources/contactstatistics.rb +14 -0
  31. data/lib/mailjet/resources/csvimport.rb +12 -0
  32. data/lib/mailjet/resources/domainstatistics.rb +14 -0
  33. data/lib/mailjet/resources/eventcallbackurl.rb +12 -0
  34. data/lib/mailjet/resources/geostatistics.rb +14 -0
  35. data/lib/mailjet/resources/graphstatistics.rb +14 -0
  36. data/lib/mailjet/resources/listrecipient.rb +12 -0
  37. data/lib/mailjet/resources/listrecipientstatistics.rb +14 -0
  38. data/lib/mailjet/resources/liststatistics.rb +14 -0
  39. data/lib/mailjet/resources/manycontacts.rb +12 -0
  40. data/lib/mailjet/resources/message.rb +12 -0
  41. data/lib/mailjet/resources/messagehistory.rb +14 -0
  42. data/lib/mailjet/resources/messageinformation.rb +14 -0
  43. data/lib/mailjet/resources/messagesentstatistics.rb +14 -0
  44. data/lib/mailjet/resources/messagestate.rb +12 -0
  45. data/lib/mailjet/resources/messagestatistics.rb +14 -0
  46. data/lib/mailjet/resources/metadata.rb +14 -0
  47. data/lib/mailjet/resources/metasender.rb +12 -0
  48. data/lib/mailjet/resources/myprofile.rb +12 -0
  49. data/lib/mailjet/resources/newsletter.rb +12 -0
  50. data/lib/mailjet/resources/newsletterblock.rb +12 -0
  51. data/lib/mailjet/resources/newsletterproperties.rb +12 -0
  52. data/lib/mailjet/resources/newslettertemplate.rb +12 -0
  53. data/lib/mailjet/resources/newslettertemplateblock.rb +12 -0
  54. data/lib/mailjet/resources/newslettertemplatecategory.rb +12 -0
  55. data/lib/mailjet/resources/newslettertemplateproperties.rb +12 -0
  56. data/lib/mailjet/resources/openinformation.rb +14 -0
  57. data/lib/mailjet/resources/openstatistics.rb +14 -0
  58. data/lib/mailjet/resources/parseroute.rb +12 -0
  59. data/lib/mailjet/resources/preferences.rb +12 -0
  60. data/lib/mailjet/resources/sender.rb +12 -0
  61. data/lib/mailjet/resources/senderstatistics.rb +14 -0
  62. data/lib/mailjet/resources/toplinkclicked.rb +14 -0
  63. data/lib/mailjet/resources/trigger.rb +12 -0
  64. data/lib/mailjet/resources/user.rb +12 -0
  65. data/lib/mailjet/resources/useragentstatistics.rb +14 -0
  66. data/lib/mailjet/resources/widget.rb +12 -0
  67. data/lib/mailjet/resources/widgetcustomvalue.rb +12 -0
  68. data/lib/mailjet/version.rb +1 -1
  69. metadata +155 -44
  70. data/lib/mailjet/api.rb +0 -20
  71. data/lib/mailjet/api_request.rb +0 -70
  72. data/lib/mailjet/campaign.rb +0 -67
  73. data/lib/mailjet/click.rb +0 -15
  74. data/lib/mailjet/contact.rb +0 -18
  75. data/lib/mailjet/email.rb +0 -4
  76. data/lib/mailjet/list.rb +0 -58
  77. data/lib/mailjet/template_category.rb +0 -13
  78. data/lib/mailjet/template_model.rb +0 -13
  79. data/test/mailjet/api_request_test.rb +0 -72
  80. data/test/mailjet/api_test.rb +0 -13
  81. data/test/mailjet/campaign_test.rb +0 -66
  82. data/test/mailjet/configuration_test.rb +0 -16
  83. data/test/mailjet/contact_test.rb +0 -24
  84. data/test/mailjet/list_test.rb +0 -67
  85. data/test/mailjet/rack/endpoint_test.rb +0 -30
  86. data/test/mailjet/reporting_test.rb +0 -26
  87. data/test/mailjet/template_category_test.rb +0 -13
  88. data/test/mailjet/template_model_test.rb +0 -13
  89. data/test/mailjet_test.rb +0 -17
  90. data/test/minitest_helper.rb +0 -22
@@ -1,16 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::Configuration do
4
- describe "accessors" do
5
- it "should memorize values" do
6
- Mailjet::Configuration.api_key = '1234'
7
- Mailjet::Configuration.api_key.must_equal '1234'
8
- end
9
- end
10
-
11
- describe "#use_https" do
12
- it "should be true by default" do
13
- Mailjet::Configuration.use_https.must_equal true
14
- end
15
- end
16
- end
@@ -1,24 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::Contact do
4
- it 'has an integration suite, tested directly against Mailjet service' do
5
- # init
6
- Mailjet::List.all.each do |list|
7
- list.delete
8
- end
9
- list = Mailjet::List.create(:label => 'My Mailjet list', :name => "mymailjetlist")
10
- list.add_contacts("c1@contacts.com")
11
-
12
- # Mailjet::Contact.all
13
- contacts = Mailjet::Contact.all
14
- contacts.wont_be_empty # we can't empty the whole contact list...
15
- contacts.first.must_be_instance_of Mailjet::Contact
16
-
17
- # Mailjet::Contact.all(:openers => true)
18
- # Mailjet::Contact.all(:openers => true).must_be_empty
19
- # TODO :openers does not work, times out
20
-
21
- # Mailjet::Contact#infos
22
- contacts.first.infos["click"].wont_be_nil
23
- end
24
- end
@@ -1,67 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::List do
4
- it 'has an integration suite, tested directly against Mailjet service' do
5
- # clean-up all existing lists:
6
- Mailjet::List.all.each do |list|
7
- list.delete
8
- end
9
-
10
- # Mailjet::List.all for no lists
11
- Mailjet::List.all.must_be_empty
12
-
13
- # Mailjet::List#create
14
- list = Mailjet::List.create(:label => 'My Mailjet list', :name => "mymailjetlist")
15
- list.must_be_instance_of Mailjet::List
16
- list.label.must_equal 'My Mailjet list'
17
- list.name.must_equal 'mymailjetlist'
18
-
19
- # Mailjet::List#update.
20
- list.update(:label => 'My updated Mailjet list', :name => "myupdatedmailjetlist").must_equal "OK"
21
- updated_list = Mailjet::List.all.first
22
- updated_list.label.must_equal 'My updated Mailjet list'
23
- updated_list.name.must_equal 'myupdatedmailjetlist'
24
- updated_list.id.must_equal list.id
25
-
26
- # Mailjet::List.all
27
- lists = Mailjet::List.all
28
- lists.count.must_equal 1
29
- lists.first.must_be_instance_of Mailjet::List
30
- lists.first.id.must_equal updated_list.id
31
-
32
- # Mailjet::List#add_contacts
33
- list.add_contacts.must_equal "NotModified"
34
- list.add_contacts("c1@contacts.com").must_equal "OK"
35
- list.add_contacts("c1@contacts.com").must_equal "NotModified"
36
- list.add_contacts("c2@contacts.com", "c3@contacts.com").must_equal "OK"
37
- list.add_contacts("c4@contacts.com", "c5@contacts.com").must_equal "OK"
38
-
39
- # Mailjet::List#contacts and validate results of add_contacts
40
- contacts = list.contacts
41
- contacts.first.must_be_instance_of Mailjet::Contact
42
- contacts.map(&:email).sort.must_equal ["c1@contacts.com", "c2@contacts.com", "c3@contacts.com", "c4@contacts.com", "c5@contacts.com"]
43
-
44
- # Mailjet::List#unsubscribe_contact
45
- list.unsubscribe_contact("c1@contacts.com").must_equal "OK"
46
- exception = proc {list.unsubscribe_contact("c1@contacts.com")}.must_raise(Mailjet::ApiError)
47
- exception.to_s.must_match /This contact is already unsub./
48
-
49
- # Mailjet::List#remove_contacts
50
- list.remove_contacts.must_equal "NotModified"
51
- list.remove_contacts("does-not-exist@nowhere.com").must_equal "NotModified"
52
- list.remove_contacts("c1@contacts.com", "c2@contacts.com").must_equal "OK"
53
- list.contacts.count.must_equal 3
54
-
55
- # Mailjet::List#email
56
- list.email.must_match /\@lists\.mailjet\.com$/
57
-
58
- # Mailjet::List#statistics
59
- list.statistics["sent"].must_equal "0"
60
-
61
- # Mailjet::List#delete
62
- list.delete.must_equal 'OK'
63
- Mailjet::List.all.must_be_empty
64
- exception = proc { list.delete }.must_raise(Mailjet::ApiError)
65
- exception.to_s.must_match /This ID not appears to be an active list on your account/
66
- end
67
- end
@@ -1,30 +0,0 @@
1
- require 'minitest_helper'
2
- require 'rack/mock'
3
-
4
- SAMPLE_MAILJET_PAYLOAD = "{\"event\":\"open\",\"time\":1331581827,\"email\":\"benoit.benezech+1634@gmail.com\",\"mj_campaign_id\":\"105881975\",\"mj_contact_id\":\"116408391\",\"customcampaign\":null,\"ip\":\"88.164.20.58\",\"geo\":\"FR\",\"agent\":\"Mozilla\\/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit\\/535.11 (KHTML, like Gecko) Chrome\\/17.0.963.79 Safari\\/535.11\"}"
5
- SAMPLE_MAILJET_PARAMS = {"event"=>"open", "time"=>1331581827, "email"=>"benoit.benezech+1634@gmail.com", "mj_campaign_id"=>"105881975", "mj_contact_id"=>"116408391", "customcampaign"=>nil, "ip"=>"88.164.20.58", "geo"=>"FR", "agent"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.79 Safari/535.11"}
6
-
7
-
8
- describe Mailjet::Rack::Endpoint do
9
- it "should decipher Mailjet's posted events and pass them to the block" do
10
- # mock should receive :find with "benoit.benezech+1634@gmail.com" and will return true
11
- $user_class_mock = MiniTest::Mock.new.expect(:find, true, ["benoit.benezech+1634@gmail.com"])
12
-
13
- app = Rack::Builder.new do
14
- use Rack::Lint
15
- use Mailjet::Rack::Endpoint, '/callback' do |params|
16
- $user_class_mock.find(params['email'])#.do_smtg_with_the_user....
17
- end
18
- run lambda { |env|
19
- [200, {'Content-Type' => 'text/plain'}, ['passed through your endpoint, haha']]
20
- }
21
- end
22
-
23
- response = Rack::MockRequest.new(app).get('/not_callback')
24
- response.body.must_equal('passed through your endpoint, haha')
25
-
26
- response = Rack::MockRequest.new(app).post('/callback', :input => SAMPLE_MAILJET_PAYLOAD)
27
- response.body.must_equal('')
28
- $user_class_mock.verify
29
- end
30
- end
@@ -1,26 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::Reporting do
4
- it 'has an integration suite, tested directly against Mailjet service' do
5
- # Mailjet::Reporting.clicks
6
- Mailjet::Reporting.clicks.must_be_instance_of Array
7
-
8
- # Mailjet::Reporting.domains
9
- Mailjet::Reporting.domains.must_be_instance_of Array
10
-
11
- # Mailjet::Reporting.clients
12
- Mailjet::Reporting.clients.must_be_instance_of Array
13
-
14
- # Mailjet::Reporting.emails
15
- Mailjet::Reporting.emails.must_be_instance_of Array
16
-
17
- # Mailjet::Reporting.statistics
18
- Mailjet::Reporting.statistics["cnt_messages"].wont_be_nil
19
-
20
- # Mailjet::Reporting.geolocation
21
- Mailjet::Reporting.geolocation.must_be_instance_of Array
22
-
23
- # Mailjet::Reporting.agents
24
- Mailjet::Reporting.agents.must_be_instance_of Array
25
- end
26
- end
@@ -1,13 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::TemplateCategory do
4
- it 'has an integration suite, tested directly against Mailjet service' do
5
-
6
- # Mailjet::TemplateCategory.all
7
- models = Mailjet::TemplateCategory.all
8
- models.wont_be_empty
9
- model = models.find{|m| m.id == "2"} # from default Mailjet templates
10
- model.must_be_instance_of Mailjet::TemplateCategory
11
- model.label.must_equal "basic"
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet::TemplateModel do
4
- it 'has an integration suite, tested directly against Mailjet service' do
5
-
6
- # Mailjet::TemplateModel.all
7
- models = Mailjet::TemplateModel.all
8
- models.wont_be_empty
9
- model = models.find{|t| t.id == '4'} # from default Mailjet templates
10
- model.must_be_instance_of Mailjet::TemplateModel
11
- model.name == "Text"
12
- end
13
- end
data/test/mailjet_test.rb DELETED
@@ -1,17 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Mailjet do
4
- describe "#configure" do
5
- it "should permit to set api keys and remember them" do
6
- Mailjet.configure do |config|
7
- config.api_key = "1234"
8
- config.secret_key = "5678"
9
- config.default_from = "default from test"
10
- end
11
-
12
- Mailjet.config.api_key.must_equal "1234"
13
- Mailjet.config.secret_key.must_equal "5678"
14
- Mailjet.config.default_from = "default from test"
15
- end
16
- end
17
- end
@@ -1,22 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'minitest/matchers'
3
- require "mocha"
4
- require 'mailjet'
5
- require 'turn'
6
-
7
- test_account = YAML::load(File.new(File.expand_path("../../config.yml", __FILE__)))['mailjet']
8
-
9
- MiniTest::Spec.before do
10
- Mailjet.configure do |config|
11
- config.api_key = test_account['api_key']
12
- config.secret_key = test_account['secret_key']
13
- config.default_from = test_account['default_from']
14
- end
15
- end
16
-
17
- MiniTest::Spec.after do
18
- Object.send(:remove_const, 'Mailjet')
19
- Dir["#{File.dirname(__FILE__)}/../lib/**/*.rb"].each {|f| load f}
20
- end
21
-
22
- Turn.config.format = :outline