uni_sender 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - jruby-18mode
6
+ - jruby-19mode
7
+ - rbx-18mode
8
+ - rbx-19mode
9
+ - ruby-head
10
+ - jruby-head
11
+ - 1.8.7
12
+ - ree
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in uni_sender.gemspec
4
4
  gemspec
5
+
6
+ gem 'rake'
@@ -1,5 +1,7 @@
1
1
  = UniSender
2
2
 
3
+ {<img src="https://travis-ci.org/jalkoby/uni_sender_gem.png" />}[https://travis-ci.org/jalkoby/uni_sender_gem]
4
+
3
5
  uni_sender gem provides full dev kit to access to api of unisender.com.ua. It uses method_missing method to provide flexible functionality, so all methods will return hash that represents responce of server.
4
6
 
5
7
  == Installation
@@ -20,21 +22,13 @@ client = UniSender::Client.new('your secret key')
20
22
 
21
23
  Gem provides non-sensitive style, so action getLits will equal to get_lists or Get_Lists
22
24
 
23
- For getting contacts call client.exportContacts(or export_clients ;) ). If request will be accepted client return hash in format
24
-
25
- {'result'=>{'field_names'=>[...], 'data'=>[[...], [...], ... ]}
26
-
27
- Before sent action to server gem process all parameters. If it will be String gem decode it to url standarts - no latin symbols will changed to equal codes.For example:
28
-
29
- 'Прекрасный день' will be "%D0%9F%D1%80%D0%B5%D0%BA%D1%80%D0%B0%D1%81%D0%BD%D1%8B%D0%B9%20%D0%B4%D0%B5%D0%BD%D1%8C"
30
-
31
- If parameter are array, uni_sender will join contents by ","(comma), also process all item like string
25
+ By default gem use english version of api. But you can change to another.
32
26
 
33
- :sample => [233, 'foo', 545] will sample=233,foo,545
27
+ UniSender::Client.new('api key', 'ru') #use russian language
34
28
 
35
- Hash will decode to variables of 2 level, for example:
29
+ If api action requires some params you can pass them via hash
36
30
 
37
- :friend=>{:name=>"Роман", :car=>"BMW"} will be friend[name]=%D0%A0%D0%BE%D0%BC%D0%B0%D0%BD&friend[car]=BMW
31
+ UniSender::Client.new('api key').import_contacts(:field_names => [ "email", "email_list_ids" ], :data => {0 => ["test@example.com", "123"] })
38
32
 
39
33
  == Dependencies
40
34
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ desc "Run all specs"
8
+ task :default => :spec
@@ -1,21 +1,20 @@
1
- require "uni_sender/version"
2
- require 'uni_sender/camelize'
3
- require 'net/http'
4
1
  require 'json'
2
+ require 'rest-client'
5
3
 
6
4
  module UniSender
5
+ URL = 'http://api.unisender.com'
7
6
 
8
7
  class Client
8
+ attr_accessor :api_key, :locale
9
9
 
10
- attr_accessor :api_key, :client_ip, :locale
11
-
12
- def initialize(api_key, params={})
10
+ def initialize(api_key, locale = nil)
13
11
  self.api_key = api_key
14
- params.each do |key, value|
15
- if defined?("#{key}=")
16
- self.send("#{key}=", value)
17
- end
12
+
13
+ if locale.is_a?(Hash)
14
+ puts "Deprecated: Initializer changed. Use UniSender::Client.new(api_key, [locale])"
15
+ locale = locale[:locale]
18
16
  end
17
+ self.locale = locale if locale
19
18
  end
20
19
 
21
20
  def locale
@@ -24,42 +23,27 @@ module UniSender
24
23
 
25
24
  private
26
25
 
27
- def translate_params(params)
28
- params.inject({}) do |iparams, couple|
29
- iparams[couple.first] = case couple.last
30
- when String
31
- URI.encode(couple.last)
32
- when Array
33
- couple.last.map{|item| URI.encode(item.to_s)}.join(',')
34
- when Hash
35
- couple.last.each do |key, value|
36
- iparams["#{couple.first}[#{key}]"] = URI.encode(value.to_s)
37
- end
38
- nil
39
- else
40
- couple.last
41
- end
42
- iparams
43
- end
44
- end
26
+ def method_missing(method_name, *args, &block)
27
+ params = (args.first.is_a?(Hash) ? args.first : {} )
28
+ default_request(prepare_action_name(method_name), params)
29
+ end
45
30
 
46
- def method_missing(undefined_action, *args, &block)
47
- params = (args.first.is_a?(Hash) ? args.first : {} )
48
- default_request(undefined_action.to_s.camelize(false), params)
49
- end
31
+ def prepare_action_name(source)
32
+ parts = source.to_s.scan(/[[:alnum:]]+/)
33
+ camelize = lambda { |word, first| (first ? word[0].chr.downcase : word[0].chr.upcase) + word[1..-1] }
50
34
 
51
- def default_request(action, params={})
52
- params = translate_params(params) if defined?('translate_params')
53
- params.merge!({'api_key'=>api_key, 'format'=>'json'})
54
- query = make_query(params)
55
- url = URI("http://api.unisender.com/#{locale}/api/#{action}")
56
- JSON.parse(Net::HTTP.post_form(url, query).body)
57
- end
58
-
59
- def make_query(params)
60
- params.delete_if{|k,v| v.to_s.empty?}
61
- end
35
+ action_name = parts.each_with_index.map { |part, i| camelize.call(part, i.zero?) }.join('')
36
+ raise NoAction if action_name.empty?
37
+ action_name
38
+ end
62
39
 
40
+ def default_request(action, params)
41
+ params.merge!(:api_key => api_key, :format => :json)
42
+ url = "#{ URL }/#{ locale }/api/#{ action }"
43
+ JSON.parse RestClient.post(url, params)
44
+ end
63
45
  end
64
46
 
47
+ class NoAction < ::StandardError
48
+ end
65
49
  end
@@ -1,3 +1,3 @@
1
1
  module UniSender
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -2,7 +2,6 @@
2
2
  require "spec_helper"
3
3
 
4
4
  describe UniSender::Client do
5
-
6
5
  it "should get collection of contact's list" do
7
6
  answer = test_client.getLists
8
7
  answer['result'].should have(3).items
@@ -40,4 +39,9 @@ describe UniSender::Client do
40
39
  #answer['result']['activated'].should == 2 falls because of rating or test mode
41
40
  end
42
41
 
42
+ it 'should import contacts' do
43
+ answer = test_client.import_contacts(:field_names => [ "email", "email_list_ids" ], :data => {0 => ["test@example.com", "123"] })
44
+ answer.should include('result')
45
+ answer['log'].should be_nil
46
+ end
43
47
  end
@@ -8,10 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.summary = %q{See description}
9
9
  gem.homepage = ""
10
10
 
11
+ gem.add_dependency 'rest-client', '~> 1.6.7'
12
+ gem.add_dependency 'json', '~> 1.7.5'
11
13
  gem.add_development_dependency 'rspec'
12
- gem.add_development_dependency 'guard-rspec'
13
- gem.add_development_dependency 'ruby_gntp'
14
- gem.add_dependency 'json'
15
14
 
16
15
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
16
  gem.files = `git ls-files`.split("\n")
metadata CHANGED
@@ -1,74 +1,86 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: uni_sender
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Sergey Pchelincev
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rspec
16
- requirement: &70093363337040 !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :development
23
- prerelease: false
24
- version_requirements: *70093363337040
25
- - !ruby/object:Gem::Dependency
26
- name: guard-rspec
27
- requirement: &70093363340120 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
17
+
18
+ date: 2012-12-16 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rest-client
34
22
  prerelease: false
35
- version_requirements: *70093363340120
36
- - !ruby/object:Gem::Dependency
37
- name: ruby_gntp
38
- requirement: &70093363285100 !ruby/object:Gem::Requirement
23
+ requirement: &id001 !ruby/object:Gem::Requirement
39
24
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
44
- type: :development
45
- prerelease: false
46
- version_requirements: *70093363285100
47
- - !ruby/object:Gem::Dependency
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 1
29
+ segments:
30
+ - 1
31
+ - 6
32
+ - 7
33
+ version: 1.6.7
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
48
37
  name: json
49
- requirement: &70093363242740 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
50
40
  none: false
51
- requirements:
52
- - - ! '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 1
45
+ segments:
46
+ - 1
47
+ - 7
48
+ - 5
49
+ version: 1.7.5
55
50
  type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
56
54
  prerelease: false
57
- version_requirements: *70093363242740
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ type: :development
65
+ version_requirements: *id003
58
66
  description: Gem that provide access to unisender.com.ua api
59
- email:
67
+ email:
60
68
  - jalkoby91@gmail.com
61
69
  executables: []
70
+
62
71
  extensions: []
72
+
63
73
  extra_rdoc_files: []
64
- files:
74
+
75
+ files:
65
76
  - .gitignore
77
+ - .rspec
78
+ - .travis.yml
66
79
  - Gemfile
67
80
  - Guardfile
68
81
  - README.rdoc
69
82
  - Rakefile
70
83
  - lib/uni_sender.rb
71
- - lib/uni_sender/camelize.rb
72
84
  - lib/uni_sender/version.rb
73
85
  - spec/data_macros.rb
74
86
  - spec/functionality/common_spec.rb
@@ -77,34 +89,39 @@ files:
77
89
  - spec/spec.opt
78
90
  - spec/spec_helper.rb
79
91
  - uni_sender.gemspec
80
- homepage: ''
92
+ homepage: ""
81
93
  licenses: []
94
+
82
95
  post_install_message:
83
96
  rdoc_options: []
84
- require_paths:
97
+
98
+ require_paths:
85
99
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
100
+ required_ruby_version: !ruby/object:Gem::Requirement
87
101
  none: false
88
- requirements:
89
- - - ! '>='
90
- - !ruby/object:Gem::Version
91
- version: '0'
92
- required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
110
  none: false
94
- requirements:
95
- - - ! '>='
96
- - !ruby/object:Gem::Version
97
- version: '0'
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
98
118
  requirements: []
119
+
99
120
  rubyforge_project:
100
- rubygems_version: 1.8.15
121
+ rubygems_version: 1.8.24
101
122
  signing_key:
102
123
  specification_version: 3
103
124
  summary: See description
104
- test_files:
105
- - spec/data_macros.rb
106
- - spec/functionality/common_spec.rb
107
- - spec/functionality/managing_email_spec.rb
108
- - spec/functionality/managing_list_spec.rb
109
- - spec/spec.opt
110
- - spec/spec_helper.rb
125
+ test_files: []
126
+
127
+ has_rdoc:
@@ -1,11 +0,0 @@
1
- String.class_eval do
2
-
3
- # get from active support library
4
- def camelize(first_letter_in_uppercase = true)
5
- if first_letter_in_uppercase
6
- self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
7
- else
8
- self[0].chr.downcase + self.camelize[1..-1]
9
- end
10
- end
11
- end