openassets-ruby 0.1.8 → 0.1.9

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: 35d1f08b8298e82ae2bcc4e445f9f417229881e0
4
- data.tar.gz: f7bbece60f1d4e193be5eff4f5429056a6cf209d
3
+ metadata.gz: cf01309338f084d52c8fda8cf85695b4606d32b0
4
+ data.tar.gz: a0b83af7aaa19874a381ed21c2393caff99c095d
5
5
  SHA512:
6
- metadata.gz: ccbe3eb5168cd30fccb69e4ed58fc532d3873ddfebd9ea420a4647e48b5e0a0d8a34a3d7c5c5a9b6fadd9cd977b4a46f99b85f837c36fc637ca574b7977f241d
7
- data.tar.gz: ab571a435a7ed68a15eb84984f9a2d359d0d5071e8a8b2ab1d963f965f3f83979bd5e4ba9db2e6a20480ed79ed60a8e28590adaa2f37a15b3db8ada4b5036b5f
6
+ metadata.gz: 0552802edfa3962439b41ad80f62efcc2215bc8f1ec7c105f7d2ef3beea5c97a1d6f432137103a1360e0f96ff1b6b795c6296647f0321fe9dd259861a4da363b
7
+ data.tar.gz: d152dd700611ddfced626c6aed83b67eccba0d0257198cc427e66ee551242f78b05649ce2b84c4a4a82fabd5eba1a3dcdb1a5536f30ff286183c4e3bc8bbd2dc
@@ -0,0 +1,62 @@
1
+ require 'rest-client'
2
+
3
+ module OpenAssets
4
+ module Protocol
5
+
6
+ # The Definition of Open Asset
7
+ class AssetDefinition
8
+
9
+ attr_accessor :asset_ids
10
+ attr_accessor :name_short
11
+ attr_accessor :name
12
+ attr_accessor :contract_url
13
+ attr_accessor :issuer
14
+ attr_accessor :description
15
+ attr_accessor :description_mime
16
+ attr_accessor :type
17
+ attr_accessor :divisibility
18
+ attr_accessor :link_to_website
19
+ attr_accessor :icon_url
20
+ attr_accessor :image_url
21
+ attr_accessor :version
22
+
23
+ # Parse the JSON obtained from the json String, and create a AssetDefinition object.
24
+ # @param[String]
25
+ def self.parse_json(json)
26
+ parsed_json = JSON.parse(json)
27
+ definition = new
28
+ definition.asset_ids = parsed_json['asset_ids']
29
+ definition.name_short = parsed_json['name_short']
30
+ definition.name = parsed_json['name']
31
+ definition.contract_url = parsed_json['contract_url']
32
+ definition.issuer = parsed_json['issuer']
33
+ definition.description = parsed_json['description']
34
+ definition.description_mime = parsed_json['description_mime']
35
+ definition.type = parsed_json['type']
36
+ definition.divisibility = parsed_json['divisibility']
37
+ definition.link_to_website = parsed_json['link_to_website']
38
+ definition.icon_url = parsed_json['icon_url']
39
+ definition.image_url = parsed_json['image_url']
40
+ definition.version = parsed_json['version']
41
+ definition
42
+ end
43
+
44
+ # Parse the JSON obtained from the URL, and create a AssetDefinition object.
45
+ # @param[String] url The URL of Asset Definition.
46
+ def self.parse_url(url)
47
+ begin
48
+ parse_json(RestClient.get url, :accept => :json)
49
+ rescue => e
50
+ nil
51
+ end
52
+ end
53
+
54
+ def include_asset_id?(asset_id)
55
+ return false if asset_ids.nil? || asset_ids.empty?
56
+ asset_ids.include?(asset_id)
57
+ end
58
+
59
+ end
60
+
61
+ end
62
+ end
@@ -1,5 +1,3 @@
1
- require 'rest-client'
2
-
3
1
  module OpenAssets
4
2
  module Protocol
5
3
 
@@ -14,7 +12,7 @@ module OpenAssets
14
12
  attr_accessor :account
15
13
  attr_accessor :metadata
16
14
  attr_accessor :asset_definition_url
17
- attr_accessor :valid_asset_definition
15
+ attr_accessor :asset_definition
18
16
 
19
17
 
20
18
  # @param [Integer] value The satoshi value of the output.
@@ -43,46 +41,38 @@ module OpenAssets
43
41
 
44
42
  # get divisibility defined by asset definition file.
45
43
  def divisibility
46
- return 0 unless @valid_asset_definition
47
- json = metadata_to_json
48
- (json.nil? || json.length == 0) ? 0 : json['divisibility']
44
+ return 0 unless valid_asset_definition?
45
+ @asset_definition.divisibility
49
46
  end
50
47
 
51
48
  # get Asset definition url that is included metadata.
52
49
  private
53
50
  def load_asset_definition_url
54
- @valid_asset_definition = true
55
51
  @asset_definition_url = ''
56
52
  return if @metadata.nil? || @metadata.length == 0
57
53
  if @metadata.start_with?('u=')
58
- json = metadata_to_json
59
- if json['asset_ids'].include?(@asset_id)
54
+ @asset_definition = AssetDefinition.parse_url(metadata_url)
55
+ if valid_asset_definition?
60
56
  @asset_definition_url = metadata_url
61
57
  else
62
58
  @asset_definition_url = "The asset definition is invalid. #{metadata_url}"
63
- @valid_asset_definition = false
64
59
  end
65
60
  else
66
61
  @asset_definition_url = 'Invalid metadata format.'
67
- @valid_asset_definition = false
68
62
  end
69
63
  end
70
64
 
71
65
  private
72
- def metadata_to_json
73
- url = metadata_url
74
- if url.nil?
75
- ''
76
- else
77
- JSON.parse(RestClient.get url, :accept => :json)
78
- end
79
- end
80
66
 
81
67
  def metadata_url
82
68
  unless @metadata.nil?
83
69
  @metadata.slice(2..-1)
84
70
  end
85
71
  end
72
+
73
+ def valid_asset_definition?
74
+ !@asset_definition.nil? && @asset_definition.include_asset_id?(@asset_id)
75
+ end
86
76
  end
87
77
 
88
78
  end
@@ -3,5 +3,6 @@ module OpenAssets
3
3
  autoload :MarkerOutput, 'openassets/protocol/marker_output'
4
4
  autoload :TransactionOutput, 'openassets/protocol/transaction_output'
5
5
  autoload :OutputType, 'openassets/protocol/output_type'
6
+ autoload :AssetDefinition, 'openassets/protocol/asset_definition'
6
7
  end
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module OpenAssets
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openassets-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-06 00:00:00.000000000 Z
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bitcoin-ruby
@@ -117,6 +117,7 @@ files:
117
117
  - lib/openassets/api.rb
118
118
  - lib/openassets/error.rb
119
119
  - lib/openassets/protocol.rb
120
+ - lib/openassets/protocol/asset_definition.rb
120
121
  - lib/openassets/protocol/marker_output.rb
121
122
  - lib/openassets/protocol/output_type.rb
122
123
  - lib/openassets/protocol/transaction_output.rb
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements: []
158
159
  rubyforge_project:
159
- rubygems_version: 2.4.6
160
+ rubygems_version: 2.4.5
160
161
  signing_key:
161
162
  specification_version: 4
162
163
  summary: The implementation of the Open Assets Protocol for Ruby.