yunpian_sms 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0011d0dee558f4d2ae2722d8cbafddc79f82a0f8
4
- data.tar.gz: '04129d8f55e5672778d39c1feb7420b10a7afad6'
3
+ metadata.gz: a34e72affc14403a0c3618e90e754f4ce4e7c6b4
4
+ data.tar.gz: 7434efcaef5f9fc729d8f5f02f23dcf7166bde5b
5
5
  SHA512:
6
- metadata.gz: 7baf052d77bd4bc93dd164bcadb1d17a8fe0b68b8d42b172d71b65d8ef18215d28ed091e50059770358058c997535e1e9a0b1441b67e3cb3461f03a8867ef019
7
- data.tar.gz: 7a3a7a740dc544c849b1d2ec64faead68bc151aaacf01dbef0fc83a6ff423f01433b6930eca0c3cc73946da2be4ad86bd342017a7d5520d83c557543c79d7b35
6
+ metadata.gz: 34bfeaa8a83180d56f68298ae24145b65b509bc1ebb6a8abdff7bf7e8de4b570a4717bfae0fae4902fa655ca225620b88c963685caa9db8e2ebc4f585af5a011
7
+ data.tar.gz: b483585943c34c5b3f8b0fc12b05d1c2e6ebe107f4caf99c6565738be94fcc1a4832829166aa560b25480ce3a91bdb5d990e7a3e81c7b0c467719d939392296d
data/README.md CHANGED
@@ -33,11 +33,15 @@ require 'yunpian_sms'
33
33
  YunPianSMS.api_key = 'your api key'
34
34
 
35
35
  # template examples
36
- all_templates = YunPianSMS::Template.all
37
- all_templates.each do |element|
36
+ result = YunPianSMS::Template.all
37
+ if result.successful
38
+ result.body.each do |element|
38
39
  template_id = element["tpl_id"]
39
- template = YunPianSMS::Template.find template_id
40
- end
40
+ template = YunPianSMS::Template.find(template_id).body
41
+ end
42
+ else
43
+ # raise error
44
+ end
41
45
  ~~~
42
46
 
43
47
 
@@ -0,0 +1,10 @@
1
+ class YunPianSMS::Result
2
+
3
+ attr_reader :successful, :body
4
+
5
+ def initialize(successful, body)
6
+ @successful = successful
7
+ @body = body
8
+ end
9
+
10
+ end
@@ -1,5 +1,6 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
+ require 'yunpian_sms/result'
3
4
 
4
5
  class YunPianSMS::Template
5
6
 
@@ -24,9 +25,9 @@ class YunPianSMS::Template
24
25
  http.request req
25
26
  end
26
27
  if YunPianSMS.debug_mode && YunPianSMS.logger
27
- YunPianSMS.logger.debug "Get Templates response #{res.body}"
28
+ YunPianSMS.logger.debug "Get Templates response status: #{res.code}, body: #{res.body}"
28
29
  end
29
- JSON.parse res.body
30
+ YunPianSMS::Result.new(res.kind_of?(Net::HTTPSuccess), JSON.parse(res.body))
30
31
  end
31
32
 
32
33
  end
@@ -1,3 +1,3 @@
1
1
  module YunPianSMS
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -7,23 +7,31 @@ require 'logger'
7
7
  describe YunPianSMS do
8
8
 
9
9
  subject(:logger) { Logger.new STDOUT }
10
+ subject(:api_key) { YAML.load_file('./spec/fixtures/configuration.yml')['api_key'] }
10
11
 
11
12
  before do
12
- configuration = YAML.load_file('./spec/fixtures/configuration.yml')
13
13
  YunPianSMS.debug_mode = true
14
14
  YunPianSMS.logger = logger
15
- YunPianSMS.api_key = configuration['api_key']
16
15
  end
17
16
 
18
17
  context 'templates' do
19
18
 
20
- it 'should get all templates' do
21
- all_templates = YunPianSMS::Template.all
22
- logger.debug "all templtes #{all_templates}"
23
- all_templates.each do |element|
19
+ it 'should get error response when api key missing' do
20
+ result = YunPianSMS::Template.all
21
+ expect(result.successful).to be false
22
+ end
23
+
24
+ it 'should get all templates successfully' do
25
+ YunPianSMS.api_key = api_key
26
+ result = YunPianSMS::Template.all
27
+ expect(result.successful).to be true
28
+ logger.debug "all templtes #{result.body}"
29
+ expect(YunPianSMS::Template.find(12324235345435).successful).to be false
30
+ result.body.each do |element|
24
31
  template_id = element["tpl_id"]
25
- template = YunPianSMS::Template.find template_id
26
- logger.debug "template #{template}"
32
+ template_result = YunPianSMS::Template.find template_id
33
+ expect(template_result.successful).to be true
34
+ logger.debug "template #{template_result.body}"
27
35
  end
28
36
  end
29
37
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yunpian_sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - LCola
@@ -33,6 +33,7 @@ files:
33
33
  - LICENSE.md
34
34
  - README.md
35
35
  - lib/yunpian_sms.rb
36
+ - lib/yunpian_sms/result.rb
36
37
  - lib/yunpian_sms/template.rb
37
38
  - lib/yunpian_sms/version.rb
38
39
  - spec/yunpian_sms_spec.rb