coap 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 36ea360829046ce72e968fe067c38e687bf3de8c
4
- data.tar.gz: c9c5ab0540425a325cba51a5063b12c4f0416189
3
+ metadata.gz: c4fa88769ab252aa9e46a96259925a550baa4b31
4
+ data.tar.gz: d44c5df8e6655814f7c94ff9154556f74e26dc7b
5
5
  SHA512:
6
- metadata.gz: 2c341257f415a5cf47b59c4878898984e5e9adfd8d14a696c0d9cc4678f621e8912e5b8ba79df52b735e39eccf2a300f9c4ef5ea688fc9d752a19cb06fdde5a7
7
- data.tar.gz: f4b6bcb900c0130c53a2f234d111a0c2af0022811f425b02a36e3145a84d0aaf2d1e8645a238bd9037fdbe8dd5283718a1decc9669d39fc68954d774e92af740
6
+ metadata.gz: bfc70277f16981ea5418b8e4a445761ae49d47c6379d1027a36380f87b1001ee29890eeb4df8e87068b09a6667374633908e07f9b81505c834eae5603aba8d53
7
+ data.tar.gz: 1642b287ef80007426bee50b503c5c8cf3859e9e31d426384a09da99c5c42993ec532464b1bc9c4a846f868b961fbc5272070f5d4a480e9de97614ad5aa81bd2
data/README.md CHANGED
@@ -40,14 +40,24 @@ Or install it yourself as:
40
40
 
41
41
  ## Usage
42
42
 
43
- ### In your Ruby (on Rails) application
43
+ ### In your Application
44
44
 
45
45
  require 'coap'
46
+
46
47
  CoAP::Client.new.get_by_uri('coap://coap.me/hello').payload
48
+ => "world"
49
+
50
+ CoAP::Client.new.get('/hello', 'coap.me')
51
+ => #<struct CoRE::CoAP::Message ver=1, tt=:ack, mcode=[2, 5], mid=51490, options={:max_age=>60, :token=>366862489, :content_format=>0}, payload="world">
52
+
53
+ c = CoAP::Client.new(host: 'coap.me')
54
+ c.get('/hello')
47
55
 
48
- See `test/test_client.rb` for more examples.
56
+ See [the API documentation at
57
+ rubydoc.info](http://www.rubydoc.info/github/nning/coap/master/CoRE/CoAP/Client)
58
+ or `test/test_client.rb` for more examples.
49
59
 
50
- ### Command Line Client
60
+ ### On the Command Line
51
61
 
52
62
  The command line client supports the basic CoAP methods.
53
63
 
@@ -33,6 +33,6 @@ Gem::Specification.new do |s|
33
33
  s.add_development_dependency 'rake', '~> 10.3'
34
34
  s.add_development_dependency 'rspec', '~> 3.0'
35
35
 
36
- s.add_dependency 'celluloid-io', '~> 0.16', '>= 0.16.1'
36
+ s.add_dependency 'celluloid-io', '>= 0.16.1', '< 0.17'
37
37
  s.add_dependency 'resolv-ipv6favor', '~> 0'
38
38
  end
@@ -217,6 +217,8 @@ module CoRE
217
217
  # Preserve user options.
218
218
  message.options[:block2] = options[:block2] unless options[:block2] == nil
219
219
  message.options[:observe] = options[:observe] unless options[:observe] == nil
220
+
221
+ options.delete(:block1)
220
222
  message.options.merge!(options)
221
223
 
222
224
  log_message(:sending_message, message)
@@ -1,8 +1,8 @@
1
1
  module CoRE
2
2
  module CoAP
3
3
  class Resolver
4
- def self.address(host)
5
- a = if ENV['IPv4'].nil?
4
+ def self.address(host, force_ipv6 = false)
5
+ a = if force_ipv6
6
6
  IPv6FavorResolv.getaddress(host).to_s
7
7
  else
8
8
  Resolv.getaddress(host).to_s
@@ -11,6 +11,7 @@ module CoRE
11
11
  @max_retransmit = options[:max_retransmit] || 4
12
12
  @recv_timeout = options[:recv_timeout] || DEFAULT_RECV_TIMEOUT
13
13
  @socket = options[:socket]
14
+ @force_ipv6 = !!options[:force_ipv6]
14
15
 
15
16
  @retransmit = if options[:retransmit].nil?
16
17
  true
@@ -128,7 +129,7 @@ module CoRE
128
129
  end
129
130
  # MRI throws IPAddr::InvalidAddressError, JRuby an ArgumentError
130
131
  rescue ArgumentError
131
- host = Resolver.address(host)
132
+ host = Resolver.address(host, options[:force_ipv6])
132
133
  retry
133
134
  end
134
135
 
@@ -1,5 +1,5 @@
1
1
  module CoRE
2
2
  module CoAP
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -17,6 +17,8 @@ describe Client do
17
17
 
18
18
  describe 'modifying methods' do
19
19
  subject { Client.new(max_payload: 512) }
20
+
21
+ let(:host) { 'coap.me' }
20
22
  let(:payload) { Faker::Lorem.paragraphs(5).join("\n") }
21
23
  let(:payload_utf8) { '♥' + payload }
22
24
 
@@ -24,19 +26,19 @@ describe Client do
24
26
  describe 'with block1 option' do
25
27
  describe 'creating resource' do
26
28
  it 'should work with ASCII payload' do
27
- answer = subject.post('/large-create', 'coap.me', nil, payload)
29
+ answer = subject.post('/large-create', host, nil, payload)
28
30
  expect(answer.mcode).to eq([2, 1])
29
31
 
30
- answer = subject.get('/large-create', 'coap.me')
32
+ answer = subject.get('/large-create', host)
31
33
  expect(answer.mcode).to eq([2, 5])
32
34
  expect(answer.payload).to eq(payload)
33
35
  end
34
36
 
35
37
  it 'should work with UTF8 payload' do
36
- answer = subject.post('/large-create', 'coap.me', nil, payload_utf8)
38
+ answer = subject.post('/large-create', host, nil, payload_utf8)
37
39
  expect(answer.mcode).to eq([2, 1])
38
40
 
39
- answer = subject.get('/large-create', 'coap.me')
41
+ answer = subject.get('/large-create', host)
40
42
  expect(answer.mcode).to eq([2, 5])
41
43
  expect(answer.payload.force_encoding('utf-8')).to eq(payload_utf8)
42
44
  end
@@ -48,10 +50,10 @@ describe Client do
48
50
  describe 'with block1 option' do
49
51
  describe 'updating resource' do
50
52
  it 'should work with ASCII payload' do
51
- answer = subject.put('/large-update', 'coap.me', nil, payload)
53
+ answer = subject.put('/large-update', host, nil, payload)
52
54
  expect(answer.mcode).to eq([2, 4])
53
55
 
54
- answer = subject.get('/large-update', 'coap.me')
56
+ answer = subject.get('/large-update', host)
55
57
  expect(answer.mcode).to eq([2, 5])
56
58
  expect(answer.payload).to eq(payload)
57
59
  end
@@ -1,19 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Resolver do
4
- if ENV['IPv4'].nil?
5
- context 'ipv6' do
6
- subject { IPAddr.new(Resolver.address('orgizm.net')) }
4
+ context 'ipv6' do
5
+ subject { IPAddr.new(Resolver.address('orgizm.net', true)) }
7
6
 
8
- it { expect { subject }.not_to raise_error }
9
- it { expect(subject.ipv6?).to be(true) }
10
- end
7
+ it { expect { subject }.not_to raise_error }
8
+ it { expect(subject.ipv6?).to be(true) }
11
9
  end
12
10
 
13
11
  context 'ipv4' do
14
- subject { IPAddr.new(Resolver.address('ipv4.orgizm.net')) }
12
+ context 'from dns' do
13
+ subject { IPAddr.new(Resolver.address('ipv4.orgizm.net')) }
15
14
 
16
- it { expect { subject }.not_to raise_error }
17
- it { expect(subject.ipv4?).to be(true) }
15
+ it { expect { subject }.not_to raise_error }
16
+ it { expect(subject.ipv4?).to be(true) }
17
+ end
18
+
19
+ context 'default' do
20
+ subject { IPAddr.new(Resolver.address('orgizm.net')) }
21
+
22
+ it { expect { subject }.not_to raise_error }
23
+ it { expect(subject.ipv4?).to be(true) }
24
+ end
18
25
  end
19
26
  end
@@ -59,10 +59,8 @@ describe Transmission do
59
59
  expect(Transmission.from_host('ipv4.orgizm.net').ipv6?).to be(false)
60
60
  end
61
61
 
62
- if ENV['IPv4'].nil?
63
- it 'ipv6' do
64
- expect(Transmission.from_host('orgizm.net').ipv6?).to be(true)
65
- end
62
+ it 'ipv6' do
63
+ expect(Transmission.from_host('orgizm.net', force_ipv6: true).ipv6?).to be(true)
66
64
  end
67
65
  end
68
66
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-02-04 00:00:00.000000000 Z
13
+ date: 2015-10-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -100,22 +100,22 @@ dependencies:
100
100
  name: celluloid-io
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '0.16'
106
103
  - - ">="
107
104
  - !ruby/object:Gem::Version
108
105
  version: 0.16.1
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '0.17'
109
109
  type: :runtime
110
110
  prerelease: false
111
111
  version_requirements: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
114
- - !ruby/object:Gem::Version
115
- version: '0.16'
116
113
  - - ">="
117
114
  - !ruby/object:Gem::Version
118
115
  version: 0.16.1
116
+ - - "<"
117
+ - !ruby/object:Gem::Version
118
+ version: '0.17'
119
119
  - !ruby/object:Gem::Dependency
120
120
  name: resolv-ipv6favor
121
121
  requirement: !ruby/object:Gem::Requirement
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  version: '0'
208
208
  requirements: []
209
209
  rubyforge_project:
210
- rubygems_version: 2.4.5
210
+ rubygems_version: 2.5.0
211
211
  signing_key:
212
212
  specification_version: 4
213
213
  summary: Pure Ruby implementation of RFC 7252 (Constrained Application Protocol (CoAP))