edm 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/edm/version.rb +1 -1
  2. data/lib/edm.rb +25 -64
  3. metadata +3 -3
data/lib/edm/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Edm
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/edm.rb CHANGED
@@ -2,76 +2,37 @@ require "edm/version"
2
2
  require "net/http"
3
3
 
4
4
  module Edm
5
- def self.batch_create_contacts(key, options = {})
6
- unless key.present?
7
- raise "access key can not be blank."
5
+ class EdmClient
6
+ def initialize(account, key)
7
+ @account = account
8
+ @key = key
8
9
  end
9
- unless options[:account_key].present?
10
- raise "account key can not be blank."
11
- end
12
-
13
- unless options[:data].present?
14
- raise "data can not be blank and must be an array."
15
- end
16
- sign = generate_sign(key, options)
17
- options["sign"] = sign
18
10
 
19
- result = remote_request('post', 'http://0.0.0.0:3000/api/contacts/batch_create.json', options)
20
- return result.body
21
- end
22
-
23
- def self.create_report(key, options = {})
24
- unless options[:title].present?
25
- raise "page title can not be blank."
26
- end
27
-
28
- unless options[:subject].present?
29
- raise "mail subject can not be blank."
30
- end
31
-
32
- unless options[:account_key].present?
33
- raise "account key can not be blank."
34
- end
35
-
36
- unless options[:sender_email].present?
37
- raise "sender email can not be blank."
38
- end
39
-
40
- unless options[:send_to].present? or !["all", "groups", "contacts"].include?(options[:send_to])
41
- raise 'send_to must be "all", "groups" or "contacts".'
11
+ attr_accessor :account, :key
12
+
13
+ def api_request(url, http_method, options = {})
14
+ sign = generate_sign(options)
15
+ options["sign"] = sign
16
+ Rails.logger.debug "-------------"
17
+ result = remote_request(http_method, 'http://0.0.0.0:3000' + url, options)
18
+ return result.body
42
19
  end
43
-
44
- if options[:send_to] != 'all'
45
- unless options[:contacts_info].present?
46
- raise "For send_to is #{options[:send_to]}, you must pass contacts_info"
20
+
21
+ def generate_sign(options = {})
22
+ if options.length > 0
23
+ str = options.to_a.sort.map { |c| "#{c[0]}=#{c[1]}" }.join('&')
24
+ sign = Digest::SHA1.hexdigest("#{str}#{key}")
47
25
  end
48
26
  end
49
-
50
- unless options[:data].present?
51
- raise "data can not be blank."
52
- end
53
-
54
- unless options[:template_id].present?
55
- raise "template_id can not be blank."
56
- end
57
- sign = generate_sign(key, options)
58
- options["sign"] = sign
59
27
 
60
- result = remote_request('post', 'http://0.0.0.0:3000/api/reports.json', options)
61
- return result.body
62
- end
63
-
64
- def self.generate_sign(key, options = {})
65
- if options.length > 0
66
- str = options.to_a.sort.map { |c| "#{c[0]}=#{c[1]}" }.join('&')
67
- sign = Digest::SHA1.hexdigest("#{str}#{key}")
68
- end
69
- end
70
-
71
- def self.remote_request(http_method, url, options = {})
72
- case http_method
73
- when 'post'
74
- Net::HTTP.post_form(URI.parse(url), options)
28
+ def remote_request(http_method, url, options = {})
29
+ case http_method
30
+ when 'post'
31
+ Net::HTTP.post_form(URI.parse(url), options)
32
+ when 'get'
33
+ Net::HTTP.get(URI.parse(url))
34
+ end
75
35
  end
36
+
76
37
  end
77
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spec
16
- requirement: &70287170582780 !ruby/object:Gem::Requirement
16
+ requirement: &70333222890760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70287170582780
24
+ version_requirements: *70333222890760
25
25
  description: demohour edm api
26
26
  email:
27
27
  - lijiping@demohour.com