openactive 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
  SHA256:
3
- metadata.gz: c88ea62add4f15cd402a29d350d7186717da3c8c0b7feb3eb080f08156c0a792
4
- data.tar.gz: 0b72d6feb18932a711e2a390038aac95c6e0e028bd0b68efe61162b94d5a7939
3
+ metadata.gz: 82b696d4a30a021350671e17b0a73704ae990789611057b175e9dfb7ac1360dc
4
+ data.tar.gz: 9fa2f6b38f7a0a841b4e0a6104ad6bbc2eff6054afe94cd2e856d75ea93525f1
5
5
  SHA512:
6
- metadata.gz: b60135e0c0aa90f25f80a90219a3690fc6899886f638f0940e14a3d44d1c9f1a2204a5f654b119c9164878ed016054398690587f3232978ef49ae45db9748998
7
- data.tar.gz: 2151a398e7907a1a7f8395c547f7d2acad88c888753c121bef946306afb0052eee52c32e8e2ff909a1c33cc61d95f35c507504fd6c0798d67870c60014901fd5
6
+ metadata.gz: 957654bbfcbac075430bcf3842e4853b2477540522484e22f3ba95dc5ee6c2800532a9bb77b9e0c9b79257792187bfbc1c0b3d86d3e3dae0920e1159719ab5aa
7
+ data.tar.gz: e1e39a7cfdc09372b4f257e252fda4a45254502facda28e91c2e4c2e33b9c06145ce053add03268026b83c268aa0357b374231c27bb6783c39983d1f705d553b
data/README.md CHANGED
@@ -60,6 +60,81 @@ The OpenActive data model builds on top of Schema.org, which means that you are
60
60
 
61
61
  To reflect this, OpenActive uses inheritance to build ontop of a copy of Schema.org, these are available within the OpenActive::Models::Schema and OpenActive::Enums::Schema namespaces. And so makes it easy to use additional properties from schema.org on any given type.
62
62
 
63
+ ### Full Models Example
64
+ ```ruby
65
+ session_series = OpenActive::Models::SessionSeries.new(
66
+ name: "Virtual BODYPUMP",
67
+ description: "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast",
68
+ start_date: "2017-04-24T19:30:00-08:00",
69
+ end_date: "2017-04-24T23:00:00-08:00",
70
+ location: OpenActive::Models::Place.new(
71
+ name: "Raynes Park High School, 46A West Barnes Lane",
72
+ geo: OpenActive::Models::GeoCoordinates.new(
73
+ latitude: 51.4034423828125,
74
+ longitude: -0.2369088977575302,
75
+ )
76
+ ),
77
+ activity: OpenActive::Models::Concept.new(
78
+ id: "https://openactive.io/activity-list#5e78bcbe-36db-425a-9064-bf96d09cc351",
79
+ pref_label: "Bodypump™",
80
+ in_scheme: "https://openactive.io/activity-list"
81
+ ),
82
+ organizer: OpenActive::Models::Organization.new(
83
+ name: "Central Speedball Association",
84
+ url: "http://www.speedball-world.com"
85
+ ),
86
+ offers: [OpenActive::Models::Offer.new(
87
+ identifier: "OX-AD",
88
+ name: "Adult",
89
+ price: 3.30,
90
+ price_currency: "GBP",
91
+ url: "https://profile.everyoneactive.com/booking?Site=0140&Activities=1402CBP20150217&Culture=en-GB"
92
+ )]
93
+ )
94
+
95
+ session_series.to_json
96
+ ```
97
+ This results in
98
+
99
+ ```json
100
+ {
101
+ "@context": ["https://openactive.io/", "https://openactive.io/ns-beta"],
102
+ "@type": "SessionSeries",
103
+ "description": "This is the virtual version of the original barbell class, which will help you get lean, toned and fit - fast",
104
+ "offers": [{
105
+ "@type": "Offer",
106
+ "name": "Adult",
107
+ "url": "https://profile.everyoneactive.com/booking?Site=0140&Activities=1402CBP20150217&Culture=en-GB",
108
+ "price": "3.33",
109
+ "priceCurrency": "GBP",
110
+ "identifier": "OX-AD"
111
+ }],
112
+ "startDate": "2017-04-24T19:30:00-08:00",
113
+ "endDate": "2017-04-24T23:00:00-08:00",
114
+ "location": {
115
+ "@type": "Place",
116
+ "name": "Raynes Park High School, 46A West Barnes Lane",
117
+ "geo": {
118
+ "@type": "GeoCoordinates",
119
+ "longitude": "-0.2369088977575302e0",
120
+ "latitude": "0.514034423828125e2"
121
+ }
122
+ },
123
+ "organizer": {
124
+ "@type": "Organization",
125
+ "name": "Central Speedball Association",
126
+ "url": "http://www.speedball-world.com"
127
+ },
128
+ "activity": {
129
+ "@type": "Concept",
130
+ "@id": "https://openactive.io/activity-list#5e78bcbe-36db-425a-9064-bf96d09cc351",
131
+ "inScheme": "https://openactive.io/activity-list",
132
+ "prefLabel": "Bodypump™"
133
+ },
134
+ "name": "Virtual BODYPUMP"
135
+ }
136
+ ```
137
+
63
138
  ## RPDE Feed Publishing
64
139
 
65
140
  To publish an OpenActive data feed (see this [video explainer](https://developer.openactive.io/publishing-data/data-feeds/how-a-data-feed-works)), The OpenActive gem provides a drop-in solution to render the feed pages. This also includes validation for the underlying feed query.
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module OpenActive
2
4
  class BaseModel
3
5
  include OpenActive::Concerns::JsonLdSerializable
@@ -112,8 +114,12 @@ module OpenActive
112
114
  self.class.serialize(self, **kwargs)
113
115
  end
114
116
 
115
- def to_json(*args, schema: false, **kwargs)
116
- serialize(schema: schema).to_json(*args, **kwargs)
117
+ def to_json(schema: false, pretty: false)
118
+ serialized = serialize(schema: schema)
119
+
120
+ return JSON.pretty_generate(serialized) if pretty
121
+
122
+ serialized.to_json
117
123
  end
118
124
  end
119
125
  end
@@ -28,11 +28,29 @@ module OpenActive
28
28
 
29
29
  data["@context"] =
30
30
  [
31
+ *(schema ? ["https://schema.org"] : []),
31
32
  *obj.context,
32
- *(schema ? ["https://schema.org"] : [])
33
33
  ]
34
34
  end
35
35
 
36
+ # push @'s to the start
37
+ data = data.sort_by do |k, _v|
38
+ case k
39
+ when '@context'
40
+ 0
41
+ when '@type'
42
+ 1
43
+ when '@id'
44
+ 2
45
+ else
46
+ if k.start_with?('@')
47
+ 3
48
+ else
49
+ 4
50
+ end
51
+ end
52
+ end
53
+
36
54
  # Loop all class methods, find the getters
37
55
  # and map defined attributes, normalizing attribute name
38
56
  data = Hash[data.map do |method_name, attr_value|
@@ -68,6 +86,8 @@ module OpenActive
68
86
  parent,
69
87
  **kwargs,
70
88
  )
89
+ elsif value.is_a?(BigDecimal)
90
+ value.to_s('F')
71
91
  elsif value.is_a?(Numeric)
72
92
  value
73
93
  elsif value.nil? # let nil be nil
@@ -5,7 +5,7 @@ module OpenActive
5
5
  class TimeValidator < BaseValidator
6
6
  # https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s07.html#id2175516
7
7
  # Minor additions to make second values and timezone optional
8
- REGEX = /(?<hour>2[0-3]|[01][0-9]):?(?<minute>[0-5][0-9]):?(?<second>[0-5][0-9])?(?<timezone>Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?)?/
8
+ REGEX = /(?<hour>2[0-3]|[01][0-9]):?(?<minute>[0-5][0-9]):?(?<second>[0-5][0-9])?(?<timezone>Z|[+-](?:2[0-3]|[01][0-9])(?::?(?:[0-5][0-9]))?)?/.freeze
9
9
 
10
10
  # Coerce given value to the type the validator is validating against.
11
11
  # PLEASE NOTE: no checks are performed on the given value.
@@ -1,3 +1,3 @@
1
1
  module OpenActive
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openactive
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
  - OpenActive Community
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-03 00:00:00.000000000 Z
11
+ date: 2019-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler