socketlab 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in socketlab.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 amardaxini
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,105 @@
1
+ # Socketlab
2
+
3
+ Ruby Wrapper Of Socketlabs api (http://www.socketlabs.com/api-reference/)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'socketlab'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install socketlab
18
+
19
+ ## Usage
20
+
21
+ ### Set Socketlab Api User and Password
22
+
23
+ Socketlab.api_user=''
24
+ Socketlab.api_password=''
25
+
26
+
27
+ ### Get Account Data
28
+ # https://api.socketlabs.com/v1/accountData
29
+ account_data = Socketlab::AccountData.new
30
+ account_data.api_request({:serverId=>''})
31
+ account_data.set_response
32
+
33
+ account object returns Current Billing Period Start,Current BillingPeriod End... etc attributes refer api
34
+
35
+ ### Messages Failed
36
+
37
+
38
+ # https://api.socketlabs.com/v1/messagesFailed
39
+ # date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
40
+ # query= {:serverId=>"required",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
41
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
42
+
43
+ message = Socketlab::MessageFailed.new
44
+ message.api_request(query)
45
+ message.set_response
46
+
47
+ ### Messages Queued
48
+
49
+
50
+ # https://api.socketlabs.com/v1/messagesQueued
51
+ # date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
52
+ # query= {:serverId=>"required",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
53
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
54
+
55
+ message = Socketlab::MessageQueued.new
56
+ message.api_request(query)
57
+ message.set_response
58
+
59
+ ### Messages Processed
60
+
61
+ # https://api.socketlabs.com/v1/messagesProcessed
62
+ # date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
63
+ # query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
64
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
65
+
66
+ message = Socketlab::MessageProcessed.new
67
+ message.api_request(query)
68
+ message.set_response
69
+
70
+ ### Messages Fbl Reported
71
+
72
+ # https://api.socketlabs.com/v1/messagesFblReported
73
+ # date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
74
+ # query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
75
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
76
+
77
+ message = Socketlab::FblReport.new
78
+ message.api_request(query)
79
+ message.set_response
80
+
81
+ ### Messages Open Click
82
+
83
+ # https://api.socketlabs.com/v1/messagesOpenClick
84
+ # date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
85
+ # query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
86
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
87
+
88
+ message = Socketlab::MessageOpenClick.new
89
+ message.api_request(query)
90
+ message.set_response
91
+
92
+ It will Returns total count,pages,count,items colletion,timestamp
93
+ Item collection has different attribute like timestamp,server id,to address,from address,message id .. etc depending upon api request, for more info refer api
94
+
95
+
96
+ ### Refer http://www.socketlabs.com/api-reference/ for reference for params
97
+
98
+
99
+ ## Contributing
100
+
101
+ 1. Fork it
102
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
103
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
104
+ 4. Push to the branch (`git push origin my-new-feature`)
105
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ require "socketlab/version"
2
+ require "socketlab/socketklab_request"
3
+ require "socketlab/item"
4
+ require "socketlab/account_data"
5
+ require "socketlab/message_failed"
6
+ require "socketlab/message_failed_item"
7
+ require "socketlab/message_queued"
8
+ require "socketlab/message_queued_item"
9
+ require "socketlab/message_processed"
10
+ require "socketlab/message_processed_item"
11
+ require "socketlab/fbl_report"
12
+ require "socketlab/fbl_report_item"
13
+ require "socketlab/message_open_click"
14
+ require "socketlab/message_open_click_item"
15
+ require "socketlab/utility"
16
+
17
+ require 'httparty'
18
+ module Socketlab
19
+ BASE_URI = "api.socketlabs.com"
20
+
21
+ class << self
22
+ def api_user=(v); @api_user = v; end
23
+ def api_user; @api_user; end
24
+
25
+ def api_password=(v); @api_password = v; end
26
+ def api_password; @api_password; end
27
+
28
+ def api_version=(v); @api_version = v; end
29
+ def api_version; @api_version; end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,37 @@
1
+ module Socketlab
2
+ class AccountData < SocketlabRequest
3
+
4
+ attr_accessor :timestamp
5
+
6
+ #JSON, JSONP, XML or CSV
7
+ #query {:serverId=>"",:type=>"JSON"}
8
+ def api_request(query={:type=>"JSON"})
9
+ @query_params =query
10
+ socketlab_request("accountData")
11
+
12
+ end
13
+
14
+ # Assuming type is json
15
+ # Setting Instance variable Dynamicaly and adding attr_accessor
16
+ # :server_id, :account_id, :plan_billing_period_start,:plan_billing_period_end,:billing_period_start,:billing_period_end,
17
+ # :billing_period_message_count,:billing_period_bandwidth_count_in_bytes,:billing_period_bandwidth_count_in_gigabytes,
18
+ # :billing_period_api_count,:api_allowance,:max_api_allowance,:message_allowance,:max_message_allowance,
19
+ # :bandwidth_allowance_in_bytes,:max_bandwidth_allowance_in_bytes,:bandwidth_allowance_in_gigabytes,
20
+ # :max_bandwidth_allowance_in_gigabytes,:is_over_api_allowance,:is_over_bandwidth_allowance,:is_over_message_allowance
21
+
22
+ def set_response
23
+ if @api_response.success?
24
+ @timestamp = @api_response["timestamp"]
25
+ unless @api_response["object"].nil?
26
+ @api_response["object"].each do |attr_key,attr_val|
27
+ self.class.send :attr_accessor ,attr_key.snake_case.to_sym
28
+ self.instance_variable_set("@#{attr_key.snake_case}".to_sym,attr_val)
29
+ end
30
+ end
31
+ else
32
+ @error = @api_response.parsed_response
33
+ end
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,21 @@
1
+ module Socketlab
2
+ class FblReport < SocketlabRequest
3
+
4
+ attr_accessor :total_count,:total_pages,:count,:items,:timestamp
5
+ #JSON, JSONP, XML or CSV
6
+ #date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
7
+ #query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
8
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
9
+ def api_request(query={:type=>"JSON"})
10
+ @query_params = query
11
+ socketlab_request("messagesFblReported")
12
+ end
13
+
14
+ # Assuming type is json
15
+ def set_response
16
+ super(FblReportItem)
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Socketlab
2
+ class FblReportItem
3
+ include Socketlab::Item
4
+ attr_accessor :original_recipient,:type,:user_agent
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ module Socketlab
2
+ module Item
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+ attr_accessor :server_id,:date_time,:message_id,:mailing_id,:to_address,:from_address
10
+ end
11
+
12
+ def set_item(item_hash)
13
+ item_hash.each do |attr_key,attr_val|
14
+ item_attr = "@#{attr_key.snake_case}".to_sym
15
+ self.instance_variable_set(item_attr,attr_val)
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module Socketlab
2
+ class MessageFailed < SocketlabRequest
3
+
4
+ #JSON, JSONP, XML or CSV
5
+ #date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
6
+ #query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
7
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
8
+ def api_request(query={:type=>"JSON"})
9
+ @query_params = query
10
+ socketlab_request("messagesFailed")
11
+ end
12
+
13
+ # Assuming type is json
14
+ def set_response
15
+ super(MessageFailedItem)
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module Socketlab
2
+ class MessageFailedItem
3
+ include Socketlab::Item
4
+ attr_accessor :failure_type,:failure_code,:reason
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module Socketlab
2
+ class MessageOpenClick < SocketlabRequest
3
+ #JSON, JSONP, XML or CSV
4
+ #date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
5
+ #query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
6
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
7
+ def api_request(query={:type=>"JSON"})
8
+ @query_params = query
9
+ socketlab_request("messagesOpenClick")
10
+ end
11
+
12
+ # Assuming type is json
13
+ def set_response
14
+ super(MessageOpenClickItem)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module Socketlab
2
+ class MessageOpenClickItem
3
+ include Socketlab::Item
4
+ attr_accessor :original_recipient,:event_type
5
+ end
6
+ end
@@ -0,0 +1,22 @@
1
+ module Socketlab
2
+ class MessageProcessed < SocketlabRequest
3
+
4
+ #JSON, JSONP, XML or CSV
5
+ #date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
6
+ #query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
7
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
8
+
9
+ def api_request(query={:type=>"JSON"})
10
+ @query_params = query
11
+ socketlab_request("messagesProcessed")
12
+
13
+ end
14
+
15
+ # Assuming type is json
16
+ def set_response
17
+ super(MessageProcessedItem)
18
+ end
19
+
20
+
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ module Socketlab
2
+ class MessageProcessedItem
3
+ include Socketlab::Item
4
+ attr_accessor :disposition,:local_ip,:message_size,:response
5
+ end
6
+ end
@@ -0,0 +1,20 @@
1
+ module Socketlab
2
+ class MessageQueued < SocketlabRequest
3
+ #JSON, JSONP, XML or CSV
4
+ #date_format yyyy-mm-dd hh:mm:ss If the time is omitted it will default to 00:00:00.
5
+ #query= {:serverId=>"",:startDate=>date_format,:endDate=>date_format,:timeZone=> timeZone offset,
6
+ # mailingId=>"",:messageId=>"",:index=>"",:count=>"":type=>"JSON"}
7
+
8
+ def api_request(query={:type=>"JSON"})
9
+ @query_params = query
10
+ socketlab_request("messagesQueued")
11
+ end
12
+
13
+ # Assuming type is json
14
+ def set_response
15
+ super(MessageQueuedItem)
16
+ end
17
+
18
+
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module Socketlab
2
+ class MessageQueuedItem
3
+ include Socketlab::Item
4
+ attr_accessor :message_size,:failure_code,:reason
5
+ end
6
+ end
@@ -0,0 +1,55 @@
1
+ module Socketlab
2
+ class SocketlabRequest
3
+ attr_accessor :api_user,:api_password,:api_server,:api_version,:query_params,:error
4
+ attr_accessor :total_count,:total_pages,:count,:items,:timestamp
5
+
6
+ def initialize(api_user = nil, api_key = nil,api_server=nil,api_version=nil)
7
+ @api_user = api_user || Socketlab.api_user
8
+ @api_password = api_password || Socketlab.api_password
9
+ @api_version = api_version || Socketlab.api_version || "v1"
10
+
11
+ end
12
+
13
+ def socketlab_request(module_name)
14
+ @api_response =HTTParty.get("https://#{BASE_URI}/#{@api_version}/#{module_name}", set_request_options)
15
+ end
16
+
17
+ #default response type is json
18
+ def set_query_params_type
19
+ @query_params[:type]= @query_params[:type] || "json"
20
+ end
21
+
22
+ def set_request_options
23
+ set_query_params_type
24
+ options= {}
25
+ options[:query] = @query_params
26
+ options[:basic_auth] = {:username => @api_user, :password => @api_password}
27
+ options
28
+ end
29
+
30
+ # Assuming type is json
31
+ def set_response(item_class_name)
32
+ if @api_response.success?
33
+ @total_count = @api_response["totalCount"]
34
+ @total_pages = @api_response["totalPages"]
35
+ @count = @api_response["count"]
36
+ @timestamp = @api_response["timestamp"]
37
+ @items = []
38
+ unless @api_response["collection"].nil?
39
+ @api_response["collection"].each do |attr_item|
40
+ item = item_class_name.new
41
+ item.set_item(attr_item)
42
+ @items << item
43
+ end
44
+ end
45
+ else
46
+ @error = @api_response.parsed_response
47
+ end
48
+ end
49
+
50
+ def error?
51
+ @api_response.success?
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ class String
2
+ def snake_case
3
+ return downcase if match(/\A[A-Z]+\z/)
4
+ gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
5
+ gsub(/([a-z])([A-Z])/, '\1_\2').
6
+ downcase
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Socketlab
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'socketlab/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "socketlab"
8
+ gem.version = Socketlab::VERSION
9
+ gem.authors = ["amardaxini"]
10
+ gem.email = ["amardaxini@gmail.com"]
11
+ gem.description = %q{Ruby Wrapper Of Socketlabs API}
12
+ gem.summary = %q{Ruby Wrapper Of Socketlabs API}
13
+ gem.homepage = "https://github.com/amardaxini/socketlab"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('httparty')
20
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: socketlab
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - amardaxini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ 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
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Ruby Wrapper Of Socketlabs API
31
+ email:
32
+ - amardaxini@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - lib/socketlab.rb
43
+ - lib/socketlab/account_data.rb
44
+ - lib/socketlab/fbl_report.rb
45
+ - lib/socketlab/fbl_report_item.rb
46
+ - lib/socketlab/item.rb
47
+ - lib/socketlab/message_failed.rb
48
+ - lib/socketlab/message_failed_item.rb
49
+ - lib/socketlab/message_open_click.rb
50
+ - lib/socketlab/message_open_click_item.rb
51
+ - lib/socketlab/message_processed.rb
52
+ - lib/socketlab/message_processed_item.rb
53
+ - lib/socketlab/message_queued.rb
54
+ - lib/socketlab/message_queued_item.rb
55
+ - lib/socketlab/socketklab_request.rb
56
+ - lib/socketlab/utility.rb
57
+ - lib/socketlab/version.rb
58
+ - socketlab.gemspec
59
+ homepage: https://github.com/amardaxini/socketlab
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Ruby Wrapper Of Socketlabs API
83
+ test_files: []