plate_api 1.1.0 → 1.1.1

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
  SHA256:
3
- metadata.gz: 8d6286414ebf7faeb04ee3886b71b11b367cbb1d39138e06a96960bd73aa9012
4
- data.tar.gz: c7cf1783b9491e1dfc41399c1b93133997573723aaee8c5df04e96298a7998b1
3
+ metadata.gz: b0c558f4ea358b0ddbca4fe9b389e67c1b981b2efaf2fa209e051d56200becb4
4
+ data.tar.gz: 9608c63f10f9e5d8d62b8a24d83665c4d80f6b40a97eb9aba466d11c80986505
5
5
  SHA512:
6
- metadata.gz: 7dea1b06ec0c8ae3bbfb718f87e4bcb13bd9e2fd822d78ca51ebbf91a8fa3eceafc247174a72d9368b41b78b6f935a60363f1a67823186afe0167776077ad2ff
7
- data.tar.gz: af44af8cf34d342fe1650c137d754d57ad1323ee5f6fbc4b542706eb4b867545aba385b245e50369701cbdd5d3246458c5fca30dd604233c6a1c587ea0596dcc
6
+ metadata.gz: a2f9481b9da9bc6f958761fdf81158e4ef4d19f89240a499bc754ebd7756e34707c6c8bea059a6c636e9ccb7d554b8eb15e14725bb95870b4bd8b2d1fb5a041b
7
+ data.tar.gz: af2b1fd5d3c4fd19fbdfee8574a41a86eb15ba97347c46f230135c5f82bb6edd1f4fa1dbf8d68671f85af46370091feffa5bf7e492882a3ae7c746d4faf43683
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- plate_api (1.1.0)
4
+ plate_api (1.1.1)
5
5
  faraday (~> 0.15.4)
6
6
  faraday_middleware (~> 0.13.1)
7
7
  mimemagic (~> 0.3.3)
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test Coverage](https://api.codeclimate.com/v1/badges/1e1dafadc880983ce63a/test_coverage)](https://codeclimate.com/github/platehub/plate_api/test_coverage)
6
6
  # PlateApi
7
7
 
8
- Welcome to the PlateApi gem. This gem provides a wrapper to communicate with the Plate API, taking care of
8
+ Welcome to the PlateApi gem. This gem provides a wrapper to communicate with the [Plate API](https://api-doc.getplate.com), taking care of
9
9
  authentication.
10
10
 
11
11
  ## Installation
@@ -24,16 +24,16 @@ Or install it yourself as:
24
24
 
25
25
  $ gem install plate_api
26
26
 
27
- ## Getting started
27
+ ## Getting started (TLDR;)
28
28
 
29
29
  To get started with a simple connector:
30
30
 
31
31
  ```
32
32
  # Initialze a connector
33
- con == PlateApi::Connector.new("{{public_key}}", "{{secret_key}}")
33
+ plate_api = PlateApi.new("{{public_key}}", "{{secret_key}}")
34
34
 
35
35
  # Find information of a specific site with id == 822
36
- site = con.sites.find(822)
36
+ site = plate_api.sites.find(822)
37
37
 
38
38
  # Find all posts in this site
39
39
  posts = site.posts
@@ -47,9 +47,101 @@ element = elements.first
47
47
  element.update(body: "<h2>My new text</h2>")
48
48
  ```
49
49
 
50
+ ## Establishing a connection object
51
+
52
+ To create a connection object, representing a connection to the Plate API,
53
+ you need a public and a secret key. The [Plate API docs](https://api-doc.getplate.com) explain how to get such keys.
54
+
55
+ Given these two keys, a connection object can be established as follows:
56
+
57
+ ```
58
+ plate_api = PlateApi.new("{{public_key}}", "{{secret_key}}")
59
+ ```
60
+
61
+ The Plate API object can be used to find resources with a certain id:
62
+
63
+ ## Retrieve a resource by id.
64
+
65
+ To retrieve a resource with a specific id, do the following: (to retrieve an element with `id=12`)
66
+
67
+ ```
68
+ element = plate_api.elements.find(12)
69
+ ```
70
+
71
+ ## Create/Update/Delete resources given an object
72
+
73
+ To create a resource, you first retrieve the parent of the resource you want to create.
74
+ Second, you pass the create parameters in the `create_{{resource}}` method:
75
+
76
+ ```
77
+ column = plate_api.columns.find(12)
78
+ element = column.create_element(content_type_id: 71, some_content_parameter: "Avé moi")
79
+ ```
80
+
81
+ To update a resource:
82
+
83
+ ```
84
+ element = plate_api.element.find(36)
85
+ element.update(some_content_parameter: "New content")
86
+ ```
87
+
88
+ To delete a resource (be careful):
89
+
90
+ ```
91
+ element = plate_api.element.find(223)
92
+ element.delete
93
+ ```
94
+
95
+ ## Create/Update/Delete resources directly:
96
+
97
+ It is also possible to use the `plate_api` instance to execute actions directly,
98
+ without first retrieving the object itself.
99
+
100
+ To create a resource:
101
+
102
+ ```
103
+ column = plate_api.columns.find(12)
104
+ plate_api.elements.create(column, content_type_id: 71, some_content_parameter: "Avé moi")
105
+ ```
106
+
107
+ To update a resource :
108
+
109
+ ```
110
+ plate_api.elements.update(36, some_content_parameter: "New content")
111
+ ```
112
+
113
+ To delete a resource:
114
+
115
+ ```
116
+ plate_api.elements.delete(223)
117
+ ```
118
+
119
+ ## List child resources
120
+
121
+ To list all childs of a resource, for example to get all elements in a section:
122
+
123
+ ```
124
+ section = plate_api.sections.find(50)
125
+ all_elements = section.elements
126
+ ```
127
+
128
+ To pass some arguments to the request (like pagination, or to filter on content_type):
129
+
130
+ ```
131
+ section = plate_api.sections.find(50)
132
+ all_elements = section.elements(content_type_id: 150, page: 12, per_page: 10)
133
+ ```
134
+
135
+ To find the total amount of childs of a resource:
136
+
137
+ ```
138
+ section = plate_api.sections.find(50)
139
+ count = section.elements_total_count
140
+ ```
141
+
50
142
  ## Development
51
143
 
52
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
53
145
 
54
146
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
55
147
 
@@ -17,7 +17,7 @@ module PlateApi
17
17
  if result["data"]
18
18
  return new_object(result["data"])
19
19
  else
20
- puts "No result: #{result}"
20
+ puts "PlateApi: No success: #{result}"
21
21
  return nil
22
22
  end
23
23
  end
@@ -30,7 +30,7 @@ module PlateApi
30
30
  if result["data"]
31
31
  return new_object(result["data"])
32
32
  else
33
- puts "No result: #{result}"
33
+ puts "PlateApi: No success: #{result}"
34
34
  return nil
35
35
  end
36
36
  end
@@ -50,7 +50,7 @@ module PlateApi
50
50
  if result["data"]
51
51
  return new_object(result["data"])
52
52
  else
53
- puts "No result: #{result}"
53
+ puts "PlateApi: No success: #{result}"
54
54
  return nil
55
55
  end
56
56
  end
@@ -61,7 +61,7 @@ module PlateApi
61
61
  if result["data"]
62
62
  return new_object(result["data"])
63
63
  else
64
- puts "No result: #{result}"
64
+ puts "PlateApi: No success: #{result}"
65
65
  return nil
66
66
  end
67
67
  end
@@ -74,7 +74,17 @@ module PlateApi
74
74
  if result["data"]
75
75
  return result["data"].map{|x| new_object(x)}
76
76
  else
77
- puts "No result: #{result}"
77
+ puts "PlateApi: No success: #{result}"
78
+ return nil
79
+ end
80
+ end
81
+
82
+ def index_total_count(parent)
83
+ result = @api_connector.get(collection_path(parent.class, parent.id), per_page: 1)
84
+ if result["meta"]
85
+ return result["meta"]["pagination"]["total_records"]
86
+ else
87
+ puts "PlateApi: No success: #{result}"
78
88
  return nil
79
89
  end
80
90
  end
@@ -88,13 +88,21 @@ module PlateApi::PlateObject
88
88
 
89
89
  def self.has_many(plural_name, singular_name, klass, define_create_method=false)
90
90
  HasManyRelations[plural_name.to_s] = klass
91
- define_has_many_method(plural_name, klass)
91
+ define_has_many_methods(plural_name, klass)
92
92
  define_create_method(singular_name, klass) if define_create_method
93
93
  end
94
94
 
95
- def self.define_has_many_method(plural_name, klass)
95
+ def self.define_has_many_methods(plural_name, klass)
96
96
  define_method(plural_name.to_s) do |params={}|
97
- @object_handler.api_connector.handler(Object.const_get(klass)).index(self.class, @id, params)
97
+ @object_handler.api_connector.handler(
98
+ Object.const_get(klass)
99
+ ).index(self.class, @id, params)
100
+ end
101
+
102
+ define_method("#{plural_name}_total_count") do
103
+ @object_handler.api_connector.handler(
104
+ Object.const_get(klass)
105
+ ).index_total_count(self)
98
106
  end
99
107
  end
100
108
 
@@ -1,3 +1,3 @@
1
1
  module PlateApi
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
data/lib/plate_api.rb CHANGED
@@ -12,4 +12,7 @@ require "plate_api/put_request"
12
12
 
13
13
 
14
14
  module PlateApi
15
+ def self.new(public_key, private_key)
16
+ PlateApi::Connector.new(public_key, secret_key)
17
+ end
15
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plate_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Kortleven