prismic.io 1.0.0.preview.1 → 1.0.0.preview.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: f251fe260baae8f6d9759bdb71e67cc2754ccd2d
4
- data.tar.gz: e7e13a4e8f6c225633f7134d47a42457a8e65e4a
3
+ metadata.gz: 70b17b4fc1bdb46920e3ffb4fd498bfee2b104aa
4
+ data.tar.gz: 817d91632efa91c0a7473ab3aaf982a0589f0ffc
5
5
  SHA512:
6
- metadata.gz: 9ba102393aba6870ef0992fde91d090331368103906674ba94f75f1202ab8ed5729ce67153721a6874b52987a3e9bb1a94de88424d523c1ca7dc9959544da949
7
- data.tar.gz: e42b10fe090f8adfca57267f456896da72e4b6474743f6acceaf3ff1bae4ac03094783d11e472dfe6d11186ab05b0c4f884a3a22856780205b64151f8dee4c30
6
+ metadata.gz: aeedce9389e490287de28bae3cd068a864ee6fccc840692581c3939d33c6ec7bf5024bbd7302003146722c977488008a86df61f3a3fad2a7b6b9afc6b0b02513
7
+ data.tar.gz: cb48dfa12ff2548695f13e1d73d923d6303eda650c430e30b07c7f2ada659a2396bb1b3124f0751ad5a64f09a01d8f45810fe4c67a270fcf93a476f336668787
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+ script: bundle exec rspec spec
9
+ notifications:
10
+ email:
11
+ - evo@zenexity.com
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in truc.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem "yajl-ruby", require: 'yajl', platforms: [:ruby_19, :ruby_20]
8
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- Prismic (1.0.0.preview.1)
4
+ prismic.io (1.0.0.preview.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -11,6 +11,8 @@ GEM
11
11
  multi_json (1.8.0)
12
12
  nokogiri (1.6.0)
13
13
  mini_portile (~> 0.5.0)
14
+ nokogiri (1.6.0-java)
15
+ mini_portile (~> 0.5.0)
14
16
  rspec (2.14.1)
15
17
  rspec-core (~> 2.14.0)
16
18
  rspec-expectations (~> 2.14.0)
@@ -26,12 +28,13 @@ GEM
26
28
  yajl-ruby (1.1.0)
27
29
 
28
30
  PLATFORMS
31
+ java
29
32
  ruby
30
33
 
31
34
  DEPENDENCIES
32
- Prismic!
33
35
  bundler (~> 1.3)
34
36
  nokogiri (~> 1.6)
37
+ prismic.io!
35
38
  rspec (~> 2.14)
36
39
  simplecov (~> 0.7)
37
- yajl-ruby (~> 1.1)
40
+ yajl-ruby
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Ruby development kit for prismic.io
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/prismic.io.png)](http://badge.fury.io/rb/prismic.io)
4
+ [![Build Status](https://api.travis-ci.org/prismicio/ruby-kit.png)](https://travis-ci.org/prismicio/ruby-kit)
5
+ [![Code Climate](https://codeclimate.com/github/prismicio/ruby-kit.png)](https://codeclimate.com/github/prismicio/ruby-kit)
6
+
3
7
  ### Getting Started
4
8
 
5
9
  #### Install using bundler
@@ -15,7 +19,7 @@ gem 'prismic.io', require: 'prismic'
15
19
  Run in shell:
16
20
 
17
21
  ```sh
18
- gem install prismic.io
22
+ gem install prismic.io --pre
19
23
  ```
20
24
 
21
25
  then add in your code:
data/lib/prismic.rb CHANGED
@@ -30,9 +30,10 @@ module Prismic
30
30
  end
31
31
 
32
32
  class SearchForm
33
- attr_accessor :form, :data
33
+ attr_accessor :api, :form, :data
34
34
 
35
- def initialize(form, data=form.default_data)
35
+ def initialize(api, form, data=form.default_data)
36
+ @api = api
36
37
  @form = form
37
38
  @data = data
38
39
  end
@@ -69,7 +70,9 @@ module Prismic
69
70
  uri = URI(action)
70
71
  uri.query = URI.encode_www_form(data)
71
72
 
72
- request = Net::HTTP::Get.new(uri.request_uri)
73
+ request_uri = uri.request_uri
74
+ request_uri += (request_uri =~ /\?/ ? '&' : '?') + "access_token=#{api.access_token}" if api.access_token
75
+ request = Net::HTTP::Get.new(request_uri)
73
76
  request.add_field('Accept', 'application/json')
74
77
 
75
78
  response = Net::HTTP.new(uri.host, uri.port).start do |http|
@@ -78,7 +81,10 @@ module Prismic
78
81
 
79
82
  raise RefNotFoundException, "Ref #{ref} not found" if response.code == "404"
80
83
 
84
+ raise FormSearchException, "Error : #{response.body}" if response.code != "200"
85
+
81
86
  JSON.parse(response.body).map do |doc|
87
+ raise FormSearchException, "Error : #{doc['error']}" if doc.include?('error')
82
88
  Prismic::JsonParser.document_parser(doc)
83
89
  end
84
90
  else
@@ -96,6 +102,7 @@ module Prismic
96
102
 
97
103
  class UnsupportedFormKind < Error ; end
98
104
  class RefNotFoundException < Error ; end
105
+ class FormSearchException < Error ; end
99
106
  end
100
107
 
101
108
  class Field
@@ -138,12 +145,13 @@ module Prismic
138
145
  end
139
146
 
140
147
  class Ref
141
- attr_accessor :ref, :label, :is_master, :scheduledAt
148
+ attr_accessor :ref, :label, :is_master, :scheduled_at
142
149
 
143
- def initialize(ref, label, is_master = false)
150
+ def initialize(ref, label, is_master = false, scheduled_at = nil)
144
151
  @ref = ref
145
- @label = label.downcase
152
+ @label = label
146
153
  @is_master = is_master
154
+ @scheduled_at = scheduled_at
147
155
  end
148
156
 
149
157
  alias :master? :is_master
@@ -159,6 +167,11 @@ module Prismic
159
167
  @blk.call(doc_link)
160
168
  end
161
169
  end
170
+
171
+ def self.link_resolver(ref, &blk)
172
+ LinkResolver.new(ref, &blk)
173
+ end
174
+
162
175
  end
163
176
 
164
177
  require 'prismic/api'
data/lib/prismic/api.rb CHANGED
@@ -1,15 +1,13 @@
1
1
  module Prismic
2
2
  class API
3
- attr_accessor :refs, :bookmarks, :forms, :master, :tags, :types
4
-
5
- def initialize(args)
6
- @json = args.fetch(:json)
7
- @bookmarks = args.fetch(:bookmarks)
8
- @refs = args.fetch(:refs)
9
- @forms = args.fetch(:forms)
10
- @tags = args.fetch(:tags)
11
- @types = args.fetch(:types)
12
- self.master = refs.values.map { |ref| ref if ref.master? }.compact.first
3
+ attr_reader :json, :access_token
4
+ attr_accessor :refs, :bookmarks, :forms, :master, :tags, :types, :oauth
5
+
6
+ def initialize(json, access_token=nil)
7
+ @json = json
8
+ @access_token = access_token
9
+ yield self if block_given?
10
+ self.master = refs.values && refs.values.map { |ref| ref if ref.master? }.compact.first
13
11
  raise BadPrismicResponseError, "No master Ref found" unless master
14
12
  end
15
13
 
@@ -18,11 +16,11 @@ module Prismic
18
16
  end
19
17
 
20
18
  def ref(name)
21
- refs[name]
19
+ refs[name.downcase]
22
20
  end
23
21
 
24
- def ref_id_by_label(label)
25
- refs.find { |k, ref| k == label }.last
22
+ def master_ref
23
+ ref('master')
26
24
  end
27
25
 
28
26
  def form(name)
@@ -33,13 +31,10 @@ module Prismic
33
31
  @json
34
32
  end
35
33
 
36
- def self.get(url, token=nil)
37
- url = url + "?access_token=" + token if token
38
- puts url
39
- uri = URI(url)
34
+ def self.get(url, access_token=nil)
35
+ uri = URI(access_token ? "#{url}?access_token=#{access_token}" : url)
40
36
  http = Net::HTTP.new(uri.host)
41
- path = token ? "#{uri.path}?access_token=#{token}" : uri.path
42
- req = Net::HTTP::Get.new(path, 'Accept' => 'application/json')
37
+ req = Net::HTTP::Get.new(uri.path, 'Accept' => 'application/json')
43
38
  res = http.request(req)
44
39
 
45
40
  if res.code == '200'
@@ -49,20 +44,19 @@ module Prismic
49
44
  end
50
45
  end
51
46
 
52
- def self.start(url, token=nil)
53
- resp = get(url, token)
47
+ def self.start(url, access_token=nil)
48
+ resp = get(url, access_token)
54
49
  json = JSON.load(resp.body)
55
- parse_api_response(json)
50
+ parse_api_response(json, access_token)
56
51
  end
57
52
 
58
- def self.parse_api_response(data)
53
+ def self.parse_api_response(data, access_token=nil)
59
54
  data_forms = data['forms'] || []
60
55
  data_refs = data.fetch('refs'){ raise BadPrismicResponseError, "No refs given" }
61
- new({
62
- json: data,
63
- bookmarks: data['bookmarks'],
64
- forms: Hash[data_forms.map { |k, form|
65
- [k, SearchForm.new(Form.new(
56
+ new(data, access_token) {|api|
57
+ api.bookmarks = data['bookmarks']
58
+ api.forms = Hash[data_forms.map { |k, form|
59
+ [k, SearchForm.new(api, Form.new(
66
60
  form['name'],
67
61
  Hash[form['fields'].map { |k2, field|
68
62
  [k2, Field.new(field['type'], field['default'])]
@@ -72,13 +66,37 @@ module Prismic
72
66
  form['enctype'],
73
67
  form['action'],
74
68
  ))]
75
- }],
76
- refs: Hash[data_refs.map { |ref|
77
- [ref['label'], Ref.new(ref['ref'], ref['label'], ref['isMasterRef'])]
78
- }],
79
- tags: data['tags'],
80
- types: data['types'],
81
- })
69
+ }]
70
+ api.refs = Hash[data_refs.map { |ref|
71
+ scheduled_at = ref['scheduledAt']
72
+ [ref['label'].downcase, Ref.new(ref['ref'], ref['label'], ref['isMasterRef'], scheduled_at && Time.at(scheduled_at / 1000.0))]
73
+ }]
74
+ api.tags = data['tags']
75
+ api.types = data['types']
76
+ api.oauth = OAuth.new(data['oauth_initiate'], data['oauth_token'])
77
+ }
78
+ end
79
+
80
+ def oauth_initiate_url(opts)
81
+ oauth.initiate + "?" + {
82
+ "client_id" => opts.fetch(:client_id),
83
+ "redirect_uri" => opts.fetch(:redirect_uri),
84
+ "scope" => opts.fetch(:scope),
85
+ }.map{|kv| kv.map{|e| CGI.escape(e) }.join("=") }.join("&")
86
+ end
87
+
88
+ def oauth_check_token(params)
89
+ uri = URI(oauth.token)
90
+ res = Net::HTTP.post_form(uri, params)
91
+ if res.code == '200'
92
+ begin
93
+ JSON.parse(res.body)['access_token']
94
+ rescue Exception => e
95
+ raise PrismicWSConnectionError.new(res, e)
96
+ end
97
+ else
98
+ raise PrismicWSConnectionError, res
99
+ end
82
100
  end
83
101
 
84
102
  private
@@ -90,5 +108,13 @@ module Prismic
90
108
  super("Can't connect to Prismic's API: #{resp.code} #{resp.message}", cause)
91
109
  end
92
110
  end
111
+
112
+ class OAuth
113
+ attr_reader :initiate, :token
114
+ def initialize(initiate, token)
115
+ @initiate = initiate
116
+ @token = token
117
+ end
118
+ end
93
119
  end
94
120
  end
@@ -80,7 +80,7 @@ module Prismic
80
80
  end
81
81
  def start_html(link_resolver)
82
82
  # Quick-and-dirty way to generate the right <a> tag
83
- link.as_html(link_resolver).sub(/(<a[^>]+>).*/, '\1')
83
+ link.as_html(link_resolver).sub(/(<[^>]+>).*/, '\1')
84
84
  end
85
85
  def end_html(link_resolver=nil)
86
86
  "</a>"
@@ -144,6 +144,12 @@ module Prismic
144
144
  end
145
145
  end
146
146
 
147
+ class Preformatted < Text
148
+ def as_html(link_resolver=nil)
149
+ %(<pre>#{super}</pre>)
150
+ end
151
+ end
152
+
147
153
  class ListItem < Text
148
154
  attr_accessor :ordered
149
155
  alias :ordered? :ordered
@@ -18,11 +18,12 @@ module Prismic
18
18
  end
19
19
 
20
20
  def document_link_parser(json)
21
+ doc = json['value']['document']
21
22
  Prismic::Fragments::DocumentLink.new(
22
- json['value']['document']['id'],
23
- json['value']['document']['type'],
24
- json['value']['document']['tags'],
25
- json['value']['document']['slug'],
23
+ doc['id'],
24
+ doc['type'],
25
+ doc['tags'],
26
+ doc['slug'],
26
27
  json['value']['isBroken'])
27
28
  end
28
29
 
@@ -47,12 +48,13 @@ module Prismic
47
48
  end
48
49
 
49
50
  def embed_parser(json)
51
+ oembed = json['value']['oembed']
50
52
  Prismic::Fragments::Embed.new(
51
- json['value']['oembed']['type'],
52
- json['value']['oembed']['provider_name'],
53
- json['value']['oembed']['provider_url'],
54
- json['value']['oembed']['html'],
55
- json['value']['oembed']
53
+ oembed['type'],
54
+ oembed['provider_name'],
55
+ oembed['provider_url'],
56
+ oembed['html'],
57
+ oembed
56
58
  )
57
59
  end
58
60
 
@@ -94,12 +96,16 @@ module Prismic
94
96
  when 'paragraph'
95
97
  spans = block['spans'].map {|span| span_parser(span) }
96
98
  Prismic::Fragments::StructuredText::Block::Paragraph.new(block['text'], spans)
97
- when /^heading/
99
+ when 'preformatted'
100
+ spans = block['spans'].map {|span| span_parser(span) }
101
+ Prismic::Fragments::StructuredText::Block::Preformatted.new(block['text'], spans)
102
+ when /^heading(\d+)$/
103
+ heading = $1
98
104
  spans = block['spans'].map {|span| span_parser(span) }
99
105
  Prismic::Fragments::StructuredText::Block::Heading.new(
100
106
  block['text'],
101
107
  spans,
102
- block['type'][-1].to_i
108
+ heading.to_i
103
109
  )
104
110
  when 'o-list-item'
105
111
  spans = block['spans'].map {|span| span_parser(span) }
@@ -123,12 +129,13 @@ module Prismic
123
129
  )
124
130
  Prismic::Fragments::StructuredText::Block::Image.new(view)
125
131
  when 'embed'
132
+ boembed = block['oembed']
126
133
  embed = Prismic::Fragments::Embed.new(
127
- block['oembed']['type'],
128
- block['oembed']['provider_name'],
129
- block['oembed']['provider_url'],
130
- block['oembed']['html'],
131
- block['oembed']
134
+ boembed['type'],
135
+ boembed['provider_name'],
136
+ boembed['provider_url'],
137
+ boembed['html'],
138
+ boembed
132
139
  )
133
140
  Prismic::Fragments::StructuredText::Block::Image.new(embed)
134
141
  else
@@ -1,5 +1,5 @@
1
1
  module Prismic
2
2
 
3
- VERSION = "1.0.0.preview.1"
3
+ VERSION = "1.0.0.preview.2"
4
4
 
5
5
  end
data/prismic.gemspec CHANGED
@@ -19,7 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "yajl-ruby", "~> 1.1"
23
22
  spec.add_development_dependency "rspec", "~> 2.14"
24
23
  spec.add_development_dependency "nokogiri", "~> 1.6"
25
24
  spec.add_development_dependency "simplecov", "~> 0.7"
@@ -90,7 +90,7 @@ end
90
90
 
91
91
  describe 'Date' do
92
92
  before do
93
- @date = Prismic::Fragments::Date.new(DateTime.new(2013, 8, 7, 11, 13, 7, '+2'))
93
+ @date = Prismic::Fragments::Date.new(Time.new(2013, 8, 7, 11, 13, 7, '+02:00'))
94
94
  end
95
95
 
96
96
  describe 'as_html' do
@@ -323,6 +323,54 @@ describe 'Image' do
323
323
  end
324
324
  end
325
325
 
326
+ describe 'StructuredText::Heading' do
327
+ before do
328
+ @text = "This is a simple test."
329
+ @spans = [
330
+ Prismic::Fragments::StructuredText::Span::Em.new(5, 7),
331
+ Prismic::Fragments::StructuredText::Span::Strong.new(8, 9),
332
+ ]
333
+ end
334
+ it 'generates valid h1 html' do
335
+ @heading = 1
336
+ @block = Prismic::Fragments::StructuredText::Block::Heading.new(@text, @spans, @heading)
337
+ @block.as_html(nil).should == "<h1>This <em>is</em> <b>a</b> simple test.</h1>"
338
+ end
339
+ it 'generates valid h2 html' do
340
+ @heading = 2
341
+ @block = Prismic::Fragments::StructuredText::Block::Heading.new(@text, @spans, @heading)
342
+ @block.as_html(nil).should == "<h2>This <em>is</em> <b>a</b> simple test.</h2>"
343
+ end
344
+ end
345
+
346
+ describe 'StructuredText::Paragraph' do
347
+ before do
348
+ @text = "This is a simple test."
349
+ @spans = [
350
+ Prismic::Fragments::StructuredText::Span::Em.new(5, 7),
351
+ Prismic::Fragments::StructuredText::Span::Strong.new(8, 9),
352
+ ]
353
+ @block = Prismic::Fragments::StructuredText::Block::Paragraph.new(@text, @spans)
354
+ end
355
+ it 'generates valid html' do
356
+ @block.as_html(nil).should == "<p>This <em>is</em> <b>a</b> simple test.</p>"
357
+ end
358
+ end
359
+
360
+ describe 'StructuredText::Preformatted' do
361
+ before do
362
+ @text = "This is a simple test."
363
+ @spans = [
364
+ Prismic::Fragments::StructuredText::Span::Em.new(5, 7),
365
+ Prismic::Fragments::StructuredText::Span::Strong.new(8, 9),
366
+ ]
367
+ @block = Prismic::Fragments::StructuredText::Block::Preformatted.new(@text, @spans)
368
+ end
369
+ it 'generates valid html' do
370
+ @block.as_html(nil).should == "<pre>This <em>is</em> <b>a</b> simple test.</pre>"
371
+ end
372
+ end
373
+
326
374
  describe 'StructuredText::Image' do
327
375
  before do
328
376
  @view = Prismic::Fragments::Image::View.new('my_url', 10, 10)
@@ -348,8 +396,28 @@ describe 'StructuredText::Image' do
348
396
  end
349
397
  end
350
398
 
351
- describe 'StructuredText::Span' do
352
- describe 'as_html'
399
+ describe 'StructuredText::Hyperlink' do
400
+ before do
401
+ @link = Prismic::Fragments::DocumentLink.new(
402
+ "UdUjvt_mqVNObPeO",
403
+ "product",
404
+ ["Macaron"],
405
+ "dark-chocolate-macaron",
406
+ false # broken
407
+ )
408
+ @hyperlink = Prismic::Fragments::StructuredText::Span::Hyperlink.new(0, 0, @link)
409
+ @link_resolver = Prismic.link_resolver("master"){|doc_link| "http://localhost/#{doc_link.id}" }
410
+ end
411
+
412
+ describe 'as_html' do
413
+ it "can generate valid link" do
414
+ @hyperlink.start_html(@link_resolver).should == '<a href="http://localhost/UdUjvt_mqVNObPeO">'
415
+ end
416
+ it "can generate valid html for broken link" do
417
+ @link.broken = true
418
+ @hyperlink.start_html(@link_resolver).should == "<span>"
419
+ end
420
+ end
353
421
  end
354
422
 
355
423
  describe 'DocumentLink' do
@@ -206,6 +206,22 @@ describe 'structured_text_parser' do
206
206
  @structured_text_heading.blocks[0].level.should == 1
207
207
  end
208
208
 
209
+ it "correctly parses >h9 heading" do
210
+ json_heading = JSON.parse(<<-JSON)
211
+ {
212
+ "type": "StructuredText",
213
+ "value": [{
214
+ "type": "heading10",
215
+ "text": "Salted Caramel Macaron",
216
+ "spans": []
217
+ }]
218
+ }
219
+ JSON
220
+ @structured_text_heading = Prismic::JsonParser.structured_text_parser(json_heading)
221
+ @structured_text_heading.blocks[0].should be_a Prismic::Fragments::StructuredText::Block::Heading
222
+ @structured_text_heading.blocks[0].level.should == 10
223
+ end
224
+
209
225
  it "parses all the spans" do
210
226
  @structured_text_heading.blocks[0].spans.size.should == 1
211
227
  end
data/spec/prismic_spec.rb CHANGED
@@ -3,24 +3,25 @@ require 'spec_helper'
3
3
  describe 'Api' do
4
4
  before do
5
5
  json_representation = '{"foo": "bar"}'
6
- @api = Prismic::API.new({
7
- json: json_representation,
8
- bookmarks: {},
9
- tags: {},
10
- types: {},
11
- refs: {
6
+ @oauth_initiate_url = "https://lesbonneschoses.prismic.io/auth"
7
+ @api = Prismic::API.new(json_representation){|api|
8
+ api.bookmarks = {}
9
+ api.tags = {}
10
+ api.types = {}
11
+ api.refs = {
12
12
  'key1' => Prismic::Ref.new('ref1', 'label1'),
13
13
  'key2' => Prismic::Ref.new('ref2', 'label2'),
14
14
  'key3' => Prismic::Ref.new('ref3', 'label3', true),
15
15
  'key4' => Prismic::Ref.new('ref4', 'label4'),
16
- },
17
- forms: {
18
- 'form1' => Prismic::SearchForm.new(Prismic::Form.new('form1', {}, nil, nil, nil, nil)),
19
- 'form2' => Prismic::SearchForm.new(Prismic::Form.new('form2', {}, nil, nil, nil, nil)),
20
- 'form3' => Prismic::SearchForm.new(Prismic::Form.new('form3', {}, nil, nil, nil, nil)),
21
- 'form4' => Prismic::SearchForm.new(Prismic::Form.new('form4', {}, nil, nil, nil, nil)),
22
- },
23
- })
16
+ }
17
+ api.forms = {
18
+ 'form1' => Prismic::SearchForm.new(@api, Prismic::Form.new('form1', {}, nil, nil, nil, nil)),
19
+ 'form2' => Prismic::SearchForm.new(@api, Prismic::Form.new('form2', {}, nil, nil, nil, nil)),
20
+ 'form3' => Prismic::SearchForm.new(@api, Prismic::Form.new('form3', {}, nil, nil, nil, nil)),
21
+ 'form4' => Prismic::SearchForm.new(@api, Prismic::Form.new('form4', {}, nil, nil, nil, nil)),
22
+ }
23
+ api.oauth = Prismic::API::OAuth.new(@oauth_initiate_url, "https://lesbonneschoses.prismic.io/auth/token")
24
+ }
24
25
  end
25
26
 
26
27
  describe 'ref' do
@@ -37,7 +38,7 @@ describe 'Api' do
37
38
 
38
39
  describe 'ref_id_by_label' do
39
40
  it "returns the id of the ref" do
40
- @api.ref_id_by_label('key4').ref == 'ref4'
41
+ @api.ref('key4').ref == 'ref4'
41
42
  end
42
43
  end
43
44
 
@@ -141,7 +142,7 @@ describe 'Api' do
141
142
  end
142
143
 
143
144
  it "creates the right form's action" do
144
- @parsed.forms['pies'].action.should == 'http://lesbonneschoses.wroom.io/api/documents/search'
145
+ @parsed.forms['pies'].action.should == 'http://lesbonneschoses.prismic.io/api/documents/search'
145
146
  end
146
147
 
147
148
  it "creates forms with the right fields" do
@@ -171,6 +172,28 @@ describe 'Api' do
171
172
  JSON.parse(@json).size.should == 1
172
173
  end
173
174
  end
175
+
176
+ describe "oauth_initiate_url" do
177
+ before do
178
+ @client_id = "client_id"
179
+ @redirect_uri = "http://website/callback"
180
+ @scope = "none"
181
+ end
182
+ def oauth_initiate_url
183
+ @api.oauth_initiate_url({
184
+ client_id: @client_id,
185
+ redirect_uri: @redirect_uri,
186
+ scope: @scope,
187
+ })
188
+ end
189
+ def redirect_uri_encoded
190
+ CGI.escape(@redirect_uri)
191
+ end
192
+ it "build a valid url" do
193
+ oauth_initiate_url.should == "#@oauth_initiate_url?client_id=#@client_id&redirect_uri=#{redirect_uri_encoded}&scope=#@scope"
194
+ end
195
+ end
196
+
174
197
  end
175
198
 
176
199
  describe 'Document' do
@@ -213,24 +236,25 @@ end
213
236
 
214
237
  describe 'SearchForm' do
215
238
  before do
239
+ @api = nil
216
240
  @field = Prismic::Field.new('String', '[foo]')
217
241
  end
218
242
 
219
243
  describe 'query' do
220
244
  it "adds the query to the form's data" do
221
- @form = Prismic::SearchForm.new(Prismic::Form.new('form1', {}, nil, nil, nil, nil), {})
245
+ @form = Prismic::SearchForm.new(@api, Prismic::Form.new('form1', {}, nil, nil, nil, nil), {})
222
246
  @form.query('[bar]')
223
247
  @form.data.should == { 'q' => '[bar]' }
224
248
  end
225
249
 
226
250
  it "adds existant non-nil queries (in fields) to the form's data" do
227
- @form = Prismic::SearchForm.new(Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
251
+ @form = Prismic::SearchForm.new(@api, Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
228
252
  @form.query('[bar]')
229
253
  @form.data.should == { 'q' => '[foobar]' }
230
254
  end
231
255
 
232
256
  it "returns the form itself" do
233
- @form = Prismic::SearchForm.new(Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
257
+ @form = Prismic::SearchForm.new(@api, Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
234
258
  @form.query('[foo]').should == @form
235
259
  end
236
260
  end
@@ -36,7 +36,7 @@
36
36
  "method":"GET",
37
37
  "rel":"collection",
38
38
  "enctype":"application/x-www-form-urlencoded",
39
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
39
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
40
40
  "fields":{
41
41
  "ref":{
42
42
  "type":"String"
@@ -52,7 +52,7 @@
52
52
  "method":"GET",
53
53
  "rel":"collection",
54
54
  "enctype":"application/x-www-form-urlencoded",
55
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
55
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
56
56
  "fields":{
57
57
  "ref":{
58
58
  "type":"String"
@@ -68,7 +68,7 @@
68
68
  "method":"GET",
69
69
  "rel":"collection",
70
70
  "enctype":"application/x-www-form-urlencoded",
71
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
71
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
72
72
  "fields":{
73
73
  "ref":{
74
74
  "type":"String"
@@ -84,7 +84,7 @@
84
84
  "method":"GET",
85
85
  "rel":"collection",
86
86
  "enctype":"application/x-www-form-urlencoded",
87
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
87
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
88
88
  "fields":{
89
89
  "ref":{
90
90
  "type":"String"
@@ -100,7 +100,7 @@
100
100
  "method":"GET",
101
101
  "rel":"collection",
102
102
  "enctype":"application/x-www-form-urlencoded",
103
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
103
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
104
104
  "fields":{
105
105
  "ref":{
106
106
  "type":"String"
@@ -116,7 +116,7 @@
116
116
  "method":"GET",
117
117
  "rel":"collection",
118
118
  "enctype":"application/x-www-form-urlencoded",
119
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
119
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
120
120
  "fields":{
121
121
  "ref":{
122
122
  "type":"String"
@@ -132,7 +132,7 @@
132
132
  "method":"GET",
133
133
  "rel":"collection",
134
134
  "enctype":"application/x-www-form-urlencoded",
135
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
135
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
136
136
  "fields":{
137
137
  "ref":{
138
138
  "type":"String"
@@ -148,7 +148,7 @@
148
148
  "method":"GET",
149
149
  "rel":"collection",
150
150
  "enctype":"application/x-www-form-urlencoded",
151
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
151
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
152
152
  "fields":{
153
153
  "ref":{
154
154
  "type":"String"
@@ -164,7 +164,7 @@
164
164
  "method":"GET",
165
165
  "rel":"collection",
166
166
  "enctype":"application/x-www-form-urlencoded",
167
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
167
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
168
168
  "fields":{
169
169
  "ref":{
170
170
  "type":"String"
@@ -178,7 +178,7 @@
178
178
  "everything":{
179
179
  "method":"GET",
180
180
  "enctype":"application/x-www-form-urlencoded",
181
- "action":"http://lesbonneschoses.wroom.io/api/documents/search",
181
+ "action":"http://lesbonneschoses.prismic.io/api/documents/search",
182
182
  "fields":{
183
183
  "ref":{
184
184
  "type":"String"
@@ -188,5 +188,7 @@
188
188
  }
189
189
  }
190
190
  }
191
- }
191
+ },
192
+ "oauth_initiate": "https://lesbonneschoses.prismic.io/auth",
193
+ "oauth_token": "https://lesbonneschoses.prismic.io/auth/token"
192
194
  }
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  require 'nokogiri'
2
- require 'yajl'
2
+ begin
3
+ require 'yajl'
4
+ rescue LoadError
5
+ # ok not a big deal
6
+ end
3
7
  require 'json'
4
8
  require 'simplecov'
5
9
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prismic.io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.preview.1
4
+ version: 1.0.0.preview.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Étienne Vallette d'Osia
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-02 00:00:00.000000000 Z
12
+ date: 2013-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.3'
28
- - !ruby/object:Gem::Dependency
29
- name: yajl-ruby
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ~>
33
- - !ruby/object:Gem::Version
34
- version: '1.1'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- version: '1.1'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: rspec
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -89,6 +75,7 @@ extensions: []
89
75
  extra_rdoc_files: []
90
76
  files:
91
77
  - .gitignore
78
+ - .travis.yml
92
79
  - Gemfile
93
80
  - Gemfile.lock
94
81
  - README.md
@@ -140,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
127
  version: 1.3.1
141
128
  requirements: []
142
129
  rubyforge_project:
143
- rubygems_version: 2.0.3
130
+ rubygems_version: 2.0.6
144
131
  signing_key:
145
132
  specification_version: 4
146
133
  summary: Prismic.io development kit
@@ -154,4 +141,3 @@ test_files:
154
141
  - spec/responses_mocks/structured_text_heading.json
155
142
  - spec/responses_mocks/structured_text_paragraph.json
156
143
  - spec/spec_helper.rb
157
- has_rdoc: