wordpress-rails-connection 0.1.0

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: c58b7c505ca5ea3ef14f863a21e9bf399d039db6
4
+ data.tar.gz: 9b383594b84d23416eb3c38926bde23348a3fa3a
5
+ SHA512:
6
+ metadata.gz: f5ee4549026bc9c7b0204d7cdd6f439d2d94c525faf0167052f7f9877553b2489c1ef47ee233aff3b4971acd5e95577fbfaed45e391b6cf80d83014d8d1762ea
7
+ data.tar.gz: cda85f2d3bcba4f3483e0fcba6746d2801992db8ed4d8f867f743b9d833342a656c2d3963195607116b1c17eefd436b790e5acb1e28985be18d22b7843560645
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.2.2'
3
+
4
+ group :development, :test do
5
+ gem 'jeweler', '~> 2.0', '>= 2.0.1'
6
+ end
@@ -0,0 +1,64 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ addressable (2.5.0)
5
+ public_suffix (~> 2.0, >= 2.0.2)
6
+ builder (3.2.3)
7
+ descendants_tracker (0.0.4)
8
+ thread_safe (~> 0.3, >= 0.3.1)
9
+ faraday (0.9.2)
10
+ multipart-post (>= 1.2, < 3)
11
+ git (1.3.0)
12
+ github_api (0.11.3)
13
+ addressable (~> 2.3)
14
+ descendants_tracker (~> 0.0.1)
15
+ faraday (~> 0.8, < 0.10)
16
+ hashie (>= 1.2)
17
+ multi_json (>= 1.7.5, < 2.0)
18
+ nokogiri (~> 1.6.0)
19
+ oauth2
20
+ hashie (3.5.5)
21
+ highline (1.7.8)
22
+ jeweler (2.3.3)
23
+ builder
24
+ bundler (>= 1.0)
25
+ git (>= 1.2.5)
26
+ github_api (~> 0.11.0)
27
+ highline (>= 1.6.15)
28
+ nokogiri (>= 1.5.10)
29
+ psych (~> 2.2)
30
+ rake
31
+ rdoc
32
+ semver2
33
+ jwt (1.5.6)
34
+ mini_portile2 (2.1.0)
35
+ multi_json (1.12.1)
36
+ multi_xml (0.6.0)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.8.1)
39
+ mini_portile2 (~> 2.1.0)
40
+ oauth2 (1.3.1)
41
+ faraday (>= 0.8, < 0.12)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (>= 1.2, < 3)
46
+ psych (2.2.4)
47
+ public_suffix (2.0.5)
48
+ rack (2.0.1)
49
+ rake (12.0.0)
50
+ rdoc (5.1.0)
51
+ semver2 (3.4.2)
52
+ thread_safe (0.3.6)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ jeweler (~> 2.0, >= 2.0.1)
59
+
60
+ RUBY VERSION
61
+ ruby 2.2.2p95
62
+
63
+ BUNDLED WITH
64
+ 1.13.6
File without changes
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gem|
4
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
5
+ gem.name = "wordpress-rails-connection"
6
+ gem.summary = "Serves as a rails adapter to the Wordpress.com API."
7
+ gem.description = "Serves as a rails adapter to the Wordpress.com API."
8
+ gem.email = "blake.rego@gmail.com"
9
+ gem.homepage = "http://github.com/blakerego/wordpress-rails-connection"
10
+ gem.authors = ["Blake Rego"]
11
+ gem.add_dependency 'faraday', '~> 0.9.2'
12
+ gem.licenses = ['MIT']
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'wordpress-rails-connection'
@@ -0,0 +1,59 @@
1
+ module WordpressRailsConnection
2
+
3
+ extend ActiveSupport::Concern
4
+
5
+ def self.site_url
6
+ return "https://public-api.wordpress.com/rest/v1/sites/#{ENV['BLAKEWEB_WORDPRESS_SITE_ID']}"
7
+ end
8
+
9
+ def self.initialize(path = "", expires_in=6.hours)
10
+ Rails.cache.fetch("#{path}", :expires_in => expires_in) do
11
+ connection = Faraday.new(:url => "#{WordpressRailsConnection.site_url}#{path}") do |faraday|
12
+ faraday.adapter Faraday.default_adapter
13
+ faraday.headers['Content-Type'] = 'application/json'
14
+ end
15
+ response = connection.get
16
+ JSON.parse(response.body)
17
+ end
18
+ end
19
+
20
+ def self.posts(page=1, per_page=8)
21
+ path = "/posts?page=#{page.to_s}&number=#{per_page}"
22
+ WordpressRailsConnection.initialize(path)
23
+ end
24
+
25
+ def self.get_post_by_slug(slug)
26
+ path = "/posts/slug:#{slug}"
27
+ WordpressRailsConnection.initialize(path)
28
+ end
29
+
30
+ def self.get_post_by_id(post_id)
31
+ path = "/posts/#{post_id}"
32
+ WordpressRailsConnection.initialize(path)
33
+ end
34
+
35
+ def self.get_previous_post(date, post_id)
36
+ date = DateTime.parse(date).strftime('%F')
37
+ path = "/posts?before=#{date}&order_by=date&order=DESC"
38
+ posts_response = WordpressRailsConnection.initialize(path)
39
+ WordpressRailsConnection.get_first_different_post(post_id, posts_response)
40
+ end
41
+
42
+ def self.get_next_post(date, post_id)
43
+ date = DateTime.parse(date).strftime('%F')
44
+ path = "/posts?after=#{date}&order_by=date&order=ASC"
45
+ posts_response = WordpressRailsConnection.initialize(path)
46
+ WordpressRailsConnection.get_first_different_post(post_id, posts_response)
47
+ end
48
+
49
+ def self.get_first_different_post(post_id,posts_response)
50
+ return nil if posts_response['found'] <= 0
51
+ posts_response['posts'].each do |p|
52
+ if p['ID'].to_s != post_id
53
+ return p
54
+ end
55
+ end
56
+ nil
57
+ end
58
+
59
+ end
@@ -0,0 +1,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: wordpress-rails-connection 0.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "wordpress-rails-connection".freeze
9
+ s.version = "0.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Blake Rego".freeze]
14
+ s.date = "2017-03-18"
15
+ s.description = "Serves as a rails adapter to the Wordpress.com API.".freeze
16
+ s.email = "blake.rego@gmail.com".freeze
17
+ s.extra_rdoc_files = [
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "init.rb",
27
+ "lib/wordpress-rails-connection.rb",
28
+ "wordpress-rails-connection.gemspec"
29
+ ]
30
+ s.homepage = "http://github.com/blakerego/wordpress-rails-connection".freeze
31
+ s.licenses = ["MIT".freeze]
32
+ s.rubygems_version = "2.6.11".freeze
33
+ s.summary = "Serves as a rails adapter to the Wordpress.com API.".freeze
34
+
35
+ if s.respond_to? :specification_version then
36
+ s.specification_version = 4
37
+
38
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
39
+ s.add_development_dependency(%q<jeweler>.freeze, [">= 2.0.1", "~> 2.0"])
40
+ s.add_runtime_dependency(%q<faraday>.freeze, ["~> 0.9.2"])
41
+ else
42
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1", "~> 2.0"])
43
+ s.add_dependency(%q<faraday>.freeze, ["~> 0.9.2"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<jeweler>.freeze, [">= 2.0.1", "~> 2.0"])
47
+ s.add_dependency(%q<faraday>.freeze, ["~> 0.9.2"])
48
+ end
49
+ end
50
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordpress-rails-connection
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Blake Rego
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jeweler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.1
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 2.0.1
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: faraday
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.9.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: 0.9.2
47
+ description: Serves as a rails adapter to the Wordpress.com API.
48
+ email: blake.rego@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - Gemfile
55
+ - Gemfile.lock
56
+ - README.rdoc
57
+ - Rakefile
58
+ - VERSION
59
+ - init.rb
60
+ - lib/wordpress-rails-connection.rb
61
+ - wordpress-rails-connection.gemspec
62
+ homepage: http://github.com/blakerego/wordpress-rails-connection
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.11
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Serves as a rails adapter to the Wordpress.com API.
86
+ test_files: []