sipwizard 0.1.1 → 0.1.2

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.
@@ -1,4 +1,7 @@
1
1
  #Change log
2
2
 
3
+ ## 0.1.2 (2014-05-18)
4
+ * find_x_by({'AccountName' => '123'}) to find the x first elements with some criteria
5
+ * first_by({'AccountName' => '123'}) to find the first element with some criteria
3
6
  ## 0.1.1
4
7
  * add ability to pass config options to the connection
@@ -69,6 +69,25 @@ module Sipwizard
69
69
  self.new(result['Result'][0])
70
70
  end
71
71
 
72
+ def self.first_by(args)
73
+ relation = self.where(args).count(1)
74
+ result = Connection.new.get(API_PATH_MAP[:find], relation.relation)
75
+
76
+ return nil unless result['Success']
77
+
78
+ self.new(result['Result'][0])
79
+ end
80
+
81
+ def self.first_x_by(args)
82
+ count = args.delete(:count)
83
+ relation = self.where(args).count(count)
84
+ result = Connection.new.get(API_PATH_MAP[:find], relation.relation)
85
+
86
+ return nil unless result['Success']
87
+
88
+ result['Result'].map{ |r| self.new(r) }
89
+ end
90
+
72
91
  def self.create(params)
73
92
  payload = self.build_for_request(params)
74
93
  result = Connection.new.post(API_PATH_MAP[:create], payload)
@@ -15,10 +15,11 @@ module Sipwizard
15
15
  faraday_adapter = options.fetch(:adapter){ Faraday.default_adapter }
16
16
  api_type = options.fetch(:api_type){ :provisioning }
17
17
  params = options.fetch(:connection_params){{}}
18
+ debug_enabled = options.fetch(:debug_enabled){ false }
18
19
  @faraday_connection = Faraday.new(API_PATHS[api_type], params ) do |faraday|
19
20
  faraday.request :url_encoded #for post/put params
20
21
 
21
- faraday.response :logger
22
+ faraday.response :logger if debug_enabled
22
23
  faraday.response :raise_error
23
24
  faraday.response :json, content_type: /\bjson\z/
24
25
 
@@ -1,3 +1,3 @@
1
1
  module Sipwizard
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -19,6 +19,32 @@ describe Sipwizard::Account do
19
19
  end
20
20
  end
21
21
 
22
+ describe '.first_by(args)' do
23
+ let(:id){ settings['sensitive_data']['ID'] }
24
+
25
+ subject{ described_class.first_by({ 'ID' => id }) }
26
+
27
+ it 'returns an account' do
28
+ subject.should be_instance_of Sipwizard::Account
29
+ subject.id.should eq id
30
+ end
31
+ end
32
+
33
+ #TOOD: add more specs
34
+ describe '.first_x_by(args)' do
35
+ let(:id){ settings['sensitive_data']['ID'] }
36
+ let(:count){ 1 }
37
+
38
+ subject{ described_class.first_x_by({ 'ID' => id, count: 1 }) }
39
+
40
+ it 'returns an account' do
41
+ subject.should be_instance_of Array
42
+ account = subject.first
43
+ account.should be_instance_of Sipwizard::Account
44
+ account.id.should eq id
45
+ end
46
+ end
47
+
22
48
  describe '.create(params)' do
23
49
  let(:params) do
24
50
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sipwizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-05 00:00:00.000000000 Z
12
+ date: 2014-05-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler