directed-edge 0.3.2 → 0.3.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2c76595650ccf3e0309ebb28989be7704e2481f1
4
+ data.tar.gz: c4d8b222a018955f9efa766c85f459c3640308e9
5
+ SHA512:
6
+ metadata.gz: d38f115ff1e0f5f6b191c3227b05393848ce263a974b9c1152182945feccb69d2f891fb6da0c6cc186c64aa94b8c80e48936cf310583e6adede58c157a7398ef
7
+ data.tar.gz: f56d66c944a14f793306579fe794197360f1f40748b124d2d45014b3cf97388e44db7db0db7f4a56c0f5165d9cb0d17f295e2467826cb8706776847646053f61
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2009-2010, Directed Edge, Inc. <info@directededge.com>
1
+ Copyright (C) 2009-2016, Directed Edge, Inc. <info@directededge.com>
2
2
 
3
3
  Redistribution and use in source and binary forms, with or without
4
4
  modification, are permitted provided that the following conditions
data/Rakefile CHANGED
@@ -41,7 +41,7 @@ task :test => :check_dependencies
41
41
 
42
42
  task :default => :test
43
43
 
44
- require 'rake/rdoctask'
44
+ require 'rdoc/task'
45
45
  Rake::RDocTask.new do |rdoc|
46
46
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
47
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -1,43 +1,42 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
+ # stub: directed-edge 0.3.3 ruby lib
5
6
 
6
7
  Gem::Specification.new do |s|
7
- s.name = %q{directed-edge}
8
- s.version = "0.2.0"
8
+ s.name = "directed-edge"
9
+ s.version = "0.3.3"
9
10
 
10
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib"]
11
13
  s.authors = ["Directed Edge"]
12
- s.date = %q{2010-04-25}
13
- s.description = %q{Bindings for the Directed Edge webservices API}
14
- s.email = %q{info@directededge.com}
14
+ s.date = "2016-10-05"
15
+ s.description = "Bindings for the Directed Edge webservices API"
16
+ s.email = "info@directededge.com"
15
17
  s.extra_rdoc_files = [
16
18
  "LICENSE"
17
19
  ]
18
20
  s.files = [
19
21
  ".gitignore",
20
- "LICENSE",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION",
24
- "directed-edge.gemspec",
25
- "examples/example_store.rb",
26
- "lib/directed_edge.rb",
27
- "test/helper.rb",
28
- "test/test_directed_edge.rb"
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "directed-edge.gemspec",
27
+ "examples/example_store.rb",
28
+ "lib/directed_edge.rb",
29
+ "test/helper.rb",
30
+ "test/test_directed_edge.rb"
29
31
  ]
30
- s.homepage = %q{http://developer.directededge.com/}
31
- s.rdoc_options = ["--charset=UTF-8"]
32
- s.require_paths = ["lib"]
33
- s.rubygems_version = %q{1.3.6}
34
- s.summary = %q{Bindings for the Directed Edge webservices API}
32
+ s.homepage = "http://developer.directededge.com/"
33
+ s.rubygems_version = "2.5.1"
34
+ s.summary = "Bindings for the Directed Edge webservices API"
35
35
 
36
36
  if s.respond_to? :specification_version then
37
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
- s.specification_version = 3
37
+ s.specification_version = 4
39
38
 
40
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
40
  s.add_runtime_dependency(%q<rest-client>, [">= 0"])
42
41
  else
43
42
  s.add_dependency(%q<rest-client>, [">= 0"])
@@ -26,6 +26,21 @@ require 'rest_client'
26
26
  require 'rexml/document'
27
27
  require 'cgi'
28
28
 
29
+ module RestClient
30
+ class Resource
31
+ alias_method :original_index, :[]
32
+ def [](*args)
33
+ return original_index(*args) if args.empty? || !args[0].is_a?(Hash)
34
+ params = args.first.map do |key, value|
35
+ key = CGI.escape(key.to_s.gsub(/_[a-z]/) { |s| s[1, 1].upcase })
36
+ value = CGI.escape(value.to_s)
37
+ "#{key}=#{value}"
38
+ end
39
+ original_index('?' + params.join('&'))
40
+ end
41
+ end
42
+ end
43
+
29
44
  # The DirectedEdge module contains three classes:
30
45
  #
31
46
  # - Database - encapsulation of connection a database hosted by Directed Edge.
@@ -40,7 +55,7 @@ module DirectedEdge
40
55
 
41
56
  def []=(key, value)
42
57
  store(key, value)
43
- @insert_order = [] if @insert_order.nil?
58
+ @insert_order ||= []
44
59
  @insert_order.delete(key) if @insert_order.include?(key)
45
60
  @insert_order.push(key)
46
61
  end
@@ -80,9 +95,8 @@ module DirectedEdge
80
95
 
81
96
  # Reads an item from the database and puts it into an XML document.
82
97
 
83
- def read_document(method='', params={})
84
- method << '?' << params.map { |key, value| "#{URI.encode(key)}=#{URI.encode(value)}" }.join('&')
85
- REXML::Document.new(@resource[method].get(:accept => 'text/xml').to_s)
98
+ def read_document(method = '', params = {})
99
+ REXML::Document.new(@resource[method][params].get(:accept => 'text/xml').to_s)
86
100
  end
87
101
 
88
102
  # @return [Array] The elements from the document matching the given
@@ -204,7 +218,7 @@ module DirectedEdge
204
218
  #
205
219
  # @see Item#related
206
220
 
207
- def group_related(items=Set.new, tags=Set.new, params={})
221
+ def group_related(items = Set.new, tags = Set.new, params = {})
208
222
  if !items.is_a?(Array) || items.size < 1
209
223
  return with_properties?(params) ? InsertOrderHash.new : []
210
224
  end
@@ -268,8 +282,10 @@ module DirectedEdge
268
282
  if destination.is_a?(String)
269
283
  @database = Database.new('exporter')
270
284
  @file = File.new(destination, 'w')
285
+ @data = nil
271
286
  elsif destination.is_a?(Database)
272
287
  @database = destination
288
+ @file = nil
273
289
  @data = []
274
290
  else
275
291
  raise TypeError.new("Exporter must be passed a file name or database object.")
@@ -289,7 +305,11 @@ module DirectedEdge
289
305
 
290
306
  def finish
291
307
  write("</directededge>\n")
292
- @file ? @file.close : @database.resource['add'].put(@data.join)
308
+ if @file
309
+ @file.close
310
+ else
311
+ @database.resource[:update_method => :add].post(@data.join, :content_type => 'text/xml')
312
+ end
293
313
  end
294
314
 
295
315
  private
@@ -340,7 +360,7 @@ module DirectedEdge
340
360
  # manipulated locally and then saved back to the database by calling save.
341
361
 
342
362
  def initialize(database, id)
343
- super(database.resource[URI.escape(id, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))])
363
+ super(database.resource[CGI.escape(id)])
344
364
 
345
365
  @database = database
346
366
  @id = id
@@ -377,7 +397,7 @@ module DirectedEdge
377
397
 
378
398
  # @deprecated Use new / save instead.
379
399
 
380
- def create(links={}, tags=Set.new, properties={})
400
+ def create(links = {}, tags = Set.new, properties = {})
381
401
  warn 'DirectedEdge::Item::create has been deprecated. Use new / save instead.'
382
402
  @links[''] = links
383
403
  @tags = tags
@@ -395,16 +415,16 @@ module DirectedEdge
395
415
  #
396
416
  # @return [Item]
397
417
 
398
- def save(options={})
418
+ def save(options = {})
399
419
  if options[:overwrite] || @cached
400
- put(complete_document)
420
+ post(complete_document)
401
421
  else
402
422
 
403
423
  # The web services API allows to add or remove things incrementally.
404
424
  # Since we're not in the cached case, let's check to see which action(s)
405
425
  # are appropriate.
406
426
 
407
- put(complete_document, 'add')
427
+ post(complete_document, :update_method => :add)
408
428
 
409
429
  ### CHECKING LINKS_TO_REMOVE.EMPTY? ISN'T CORRECT ANYMORE
410
430
 
@@ -413,7 +433,7 @@ module DirectedEdge
413
433
  !@preselected_to_remove.empty? ||
414
434
  !@blacklisted_to_remove.empty? ||
415
435
  !@properties_to_remove.empty?
416
- put(removal_document, 'remove')
436
+ post(removal_document, :update_method => :subtract)
417
437
  @links_to_remove.clear
418
438
  @tags_to_remove.clear
419
439
  @properties_to_remove.clear
@@ -452,7 +472,7 @@ module DirectedEdge
452
472
  # @param [String] type Only links for the specified link-type will be
453
473
  # returned.
454
474
 
455
- def links(type='')
475
+ def links(type = '')
456
476
  read
457
477
  @links[type.to_s]
458
478
  end
@@ -554,7 +574,7 @@ module DirectedEdge
554
574
  #
555
575
  # @return [String] The item ID just linked to
556
576
 
557
- def link_to(other, weight=0, type='')
577
+ def link_to(other, weight = 0, type = '')
558
578
  raise RangeError if (weight < 0 || weight > 10)
559
579
  @links_to_remove[type.to_s].delete(other)
560
580
  @links[type.to_s][other.to_s] = weight
@@ -570,7 +590,7 @@ module DirectedEdge
570
590
  # @return [String] The item ID just unlinked from.
571
591
  # @see Item#link_to
572
592
 
573
- def unlink_from(other, type='')
593
+ def unlink_from(other, type = '')
574
594
  @links_to_remove[type.to_s].add(other.to_s) unless @cached
575
595
  @links[type.to_s].delete(other.to_s)
576
596
  other
@@ -585,7 +605,7 @@ module DirectedEdge
585
605
  # @return [Integer] The weight for a link from this item to the specified
586
606
  # item, or nil if not found.
587
607
 
588
- def weight_for(other, type='')
608
+ def weight_for(other, type = '')
589
609
  read
590
610
  @links[type.to_s][other.to_s]
591
611
  end
@@ -702,7 +722,7 @@ module DirectedEdge
702
722
  #
703
723
  # @see Item#recommended
704
724
 
705
- def related(tags=Set.new, params={})
725
+ def related(tags = Set.new, params = {})
706
726
  normalize_params!(params)
707
727
  params['tags'] = tags.to_a.join(',')
708
728
  if with_properties?(params)
@@ -741,7 +761,7 @@ module DirectedEdge
741
761
  #
742
762
  # @see Item#related
743
763
 
744
- def recommended(tags=Set.new, params={})
764
+ def recommended(tags = Set.new, params = {})
745
765
  normalize_params!(params)
746
766
  params['tags'] = tags.to_a.join(',')
747
767
  params.key?('excludeLinked') || params['excludeLinked'] = 'true'
@@ -811,12 +831,10 @@ module DirectedEdge
811
831
  end
812
832
  end
813
833
 
814
- # Uploads the changes to the Directed Edge database. The optional method
815
- # parameter may be used for either add or remove which do only incremental
816
- # updates to the item.
834
+ # Uploads the changes to the Directed Edge database.
817
835
 
818
- def put(document, method='')
819
- @resource[method].put(document.to_s, :content_type => 'text/xml')
836
+ def post(document, params = {})
837
+ @resource[params].post(document.to_s, :content_type => 'text/xml')
820
838
  end
821
839
 
822
840
  # Creates a document for an entire item including the links, tags and
@@ -834,7 +852,7 @@ module DirectedEdge
834
852
  @links_to_remove.each do |type, links|
835
853
  links.each do |link|
836
854
  element = item.add_element('link')
837
- element.add_attribute(type) unless type.empty?
855
+ element.add_attribute('type', type) unless type.empty?
838
856
  element.add_text(link.to_s.dup)
839
857
  end
840
858
  end
@@ -14,7 +14,7 @@ class TestDirectedEdge < Test::Unit::TestCase
14
14
  user = ENV['DIRECTEDEDGE_TEST_DB']
15
15
  pass = ENV['DIRECTEDEDGE_TEST_PASS']
16
16
  @database = DirectedEdge::Database.new(user, pass)
17
- @database.import('../testdb.xml')
17
+ @database.import(File.expand_path('../../../testdb.xml', __FILE__))
18
18
  end
19
19
 
20
20
  def test_exporter
@@ -67,23 +67,6 @@ class TestDirectedEdge < Test::Unit::TestCase
67
67
  assert_equal('Bar', item['name'])
68
68
  end
69
69
 
70
- def test_tags
71
- item = DirectedEdge::Item.new(@database, 'customer1')
72
- test_tag = 'test_tag'
73
-
74
- assert(!item.tags.include?(test_tag))
75
-
76
- item.add_tag(test_tag);
77
- item.save
78
-
79
- assert(item.tags.include?(test_tag))
80
-
81
- item.remove_tag(test_tag);
82
- item.save
83
-
84
- assert(!item.tags.include?(test_tag))
85
- end
86
-
87
70
  def test_items
88
71
  first_item = DirectedEdge::Item.new(@database, 'test_1')
89
72
  first_item.save
@@ -98,6 +81,12 @@ class TestDirectedEdge < Test::Unit::TestCase
98
81
  third_item.add_tag('test_tag')
99
82
  third_item.save
100
83
 
84
+ fourth_item = DirectedEdge::Item.new(@database, 'test_4')
85
+ fourth_item.link_to(first_item)
86
+ fourth_item.link_to(second_item, 1, 'test_type')
87
+ fourth_item.link_to(third_item)
88
+ fourth_item.save
89
+
101
90
  assert_equal('test_1', first_item.name)
102
91
 
103
92
  # Make sure that the number of tags / links for the first item is zero
@@ -123,6 +112,12 @@ class TestDirectedEdge < Test::Unit::TestCase
123
112
  assert(third_item.links.include?(first_item.to_s))
124
113
  assert(third_item.links.include?(second_item.to_s))
125
114
 
115
+ # Make sure that the fourth item is linked to the second item w/type
116
+
117
+ assert_equal(2, fourth_item.links.length)
118
+ assert_equal(1, fourth_item.links('test_type').length)
119
+ assert(fourth_item.links('test_type').include?(second_item.to_s))
120
+
126
121
  # Make sure that the first and second items show up in the related items for
127
122
  # the third item
128
123
 
@@ -132,8 +127,8 @@ class TestDirectedEdge < Test::Unit::TestCase
132
127
  # Since linked items are excluded from recommendations, nothing should show
133
128
  # up in the recommended items for the third item.
134
129
 
135
- assert_equal(0, third_item.recommended.length)
136
- assert_equal(1, second_item.recommended.length)
130
+ assert_equal(1, third_item.recommended.length)
131
+ assert_equal(2, second_item.recommended.length)
137
132
  assert_equal(0, second_item.recommended(['unknown_tag']).length)
138
133
  assert_equal([third_item.to_s], first_item.recommended(['test_tag']))
139
134
 
@@ -152,11 +147,21 @@ class TestDirectedEdge < Test::Unit::TestCase
152
147
 
153
148
  assert_equal(0, third_item.links.length)
154
149
 
150
+ fourth_item.unlink_from(third_item)
151
+ fourth_item.save
152
+
155
153
  # Now make sure that those items no longer show up as related items
156
154
 
157
155
  assert(!third_item.related.include?(first_item.to_s))
158
156
  assert(!third_item.related.include?(second_item.to_s))
159
157
 
158
+ # Remove the link with a type from the fourth item and assure that it was removed
159
+
160
+ fourth_item.unlink_from(first_item, 'test_type')
161
+ fourth_item.save
162
+
163
+ assert_equal(1, fourth_item.links.length)
164
+
160
165
  # Test item removal
161
166
 
162
167
  assert_equal(1, first_item.links.length)
@@ -318,8 +323,6 @@ class TestDirectedEdge < Test::Unit::TestCase
318
323
  end
319
324
 
320
325
  def test_unsafe_chars
321
- return if ENV['DIRECTEDEDGE_HOST'] == 'localhost'
322
-
323
326
  item = DirectedEdge::Item.new(@database, ';@%&!')
324
327
  item['foo'] = 'bar'
325
328
  item.save
@@ -402,7 +405,6 @@ class TestDirectedEdge < Test::Unit::TestCase
402
405
  assert_equal('product2', item.preselected[0])
403
406
  assert_equal('product3', item.preselected[1])
404
407
 
405
- related = item.related
406
408
  assert_equal('product2', item.related[0])
407
409
  assert_equal('product3', item.related[1])
408
410
 
@@ -463,17 +465,4 @@ class TestDirectedEdge < Test::Unit::TestCase
463
465
 
464
466
  assert(timed_out)
465
467
  end
466
-
467
- def test_foo
468
- business = DirectedEdge::Item.new(@database, 'business71')
469
- business.save
470
-
471
- user = DirectedEdge::Item.new(@database, 'user72')
472
- user.link_to('business71')
473
- user.save
474
-
475
- user = DirectedEdge::Item.new(@database, 'user72')
476
- user.unlink_from('business71')
477
- user.save
478
- end
479
468
  end
metadata CHANGED
@@ -1,44 +1,37 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: directed-edge
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 2
9
- version: 0.3.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.3
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Directed Edge
13
8
  autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
-
17
- date: 2011-12-01 00:00:00 +01:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: rest-client
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
25
17
  - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
30
20
  type: :runtime
31
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
32
27
  description: Bindings for the Directed Edge webservices API
33
28
  email: info@directededge.com
34
29
  executables: []
35
-
36
30
  extensions: []
37
-
38
- extra_rdoc_files:
31
+ extra_rdoc_files:
39
32
  - LICENSE
40
- files:
41
- - .gitignore
33
+ files:
34
+ - ".gitignore"
42
35
  - LICENSE
43
36
  - README.rdoc
44
37
  - Rakefile
@@ -48,35 +41,27 @@ files:
48
41
  - lib/directed_edge.rb
49
42
  - test/helper.rb
50
43
  - test/test_directed_edge.rb
51
- has_rdoc: true
52
44
  homepage: http://developer.directededge.com/
53
45
  licenses: []
54
-
46
+ metadata: {}
55
47
  post_install_message:
56
48
  rdoc_options: []
57
-
58
- require_paths:
49
+ require_paths:
59
50
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
61
- requirements:
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
62
53
  - - ">="
63
- - !ruby/object:Gem::Version
64
- segments:
65
- - 0
66
- version: "0"
67
- required_rubygems_version: !ruby/object:Gem::Requirement
68
- requirements:
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
69
58
  - - ">="
70
- - !ruby/object:Gem::Version
71
- segments:
72
- - 0
73
- version: "0"
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
74
61
  requirements: []
75
-
76
62
  rubyforge_project:
77
- rubygems_version: 1.3.6
63
+ rubygems_version: 2.5.1
78
64
  signing_key:
79
- specification_version: 3
65
+ specification_version: 4
80
66
  summary: Bindings for the Directed Edge webservices API
81
67
  test_files: []
82
-