Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0 SDK #113

Merged
merged 4 commits into from
Jan 19, 2017
Merged

2.0.0 SDK #113

merged 4 commits into from
Jan 19, 2017

Conversation

dlitvakb
Copy link
Contributor

@dlitvakb dlitvakb commented Dec 20, 2016

Fixes #109
Fixes #104
Obsoletes #84

This PR is intended to remove all legacy code from the SDK.

The API grew along the years considerably, and many hacks were put in place in order to keep up with it.

Breaking changes introduced:

  • The removal of the Client and Request objects from the Resource objects, means that for example: Link#resolve and Array#next_page now require the client as a parameter.
  • Client#entry now uses /entries?sys.id=ENTRY_ID instead of /entries/ENTRY_ID to properly resolve includes.
  • Refactor locale handling code
  • Refactor ResourceBuilder
  • Update all specs to RSpec 3
  • Removed DynamicEntry and Resource
  • Moved ContentTypeCache outside of the client into it's own class
  • Added new base BaseResource and FieldsResource classes to handle common resource attributes and fields related attributes respectively
  • Coercions are now part of ContentType, each Field knows which coercion should be applied depending on Field#type
  • Resource #inspect now provides a clearer and better output, without all the noise that was previously there
  • CustomResource was removed, now subclasses of Entry should be used instead.

@dlitvakb dlitvakb force-pushed the dl/cleanup-codebase branch from 7d2d7d7 to 7df6545 Compare January 7, 2017 13:01
@dlitvakb dlitvakb force-pushed the dl/cleanup-codebase branch from 7df6545 to 20f3d9d Compare January 7, 2017 13:13
@dlitvakb dlitvakb mentioned this pull request Jan 7, 2017
@dlitvakb dlitvakb changed the title [DO NOT MERGE] WIP 2.0.0 SDK 2.0.0 SDK Jan 13, 2017
@dlitvakb dlitvakb force-pushed the dl/cleanup-codebase branch from 4669ea6 to c7eaa68 Compare January 13, 2017 19:03
## Changed

* The removal of the Client and Request objects from the Resource objects, means that for example: Link#resolve and Array#next_page now require the client as a parameter.
* Client#entry now uses /entries?sys.id=ENTRY_ID instead of /entries/ENTRY_ID to properly resolve includes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

# Another possibility to create customized resources is to just inherit from an
# existing one:
# To then have it mapped automatically from the client,
# upon client instanciation, you set the :entry_mapping for your ContentType.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: instantiation, not instanciation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

def localized?(value)
return false unless value.is_a? ::Hash
value.keys.any? { |possible_locale| Contentful::Constants::KNOWN_LOCALES.include?(possible_locale) }
end

# Checks if value is a links
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Checks if value is a link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

property :country, Contentful::Locale
# You can define your own custom classes that inherit from Contentful::Entry.
# This allows you to define custom behaviour, for example, in this case, we want
# the :country field to act as a Contentful::Locale
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

else
false
end
def next_page(client = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I see this is the thing you were referring to in the changelog. 👍

# @private
def inspect
"<#{repr_name} total=#{total} skip=#{skip} limit=#{limit}>"
end

# Simplifies pagination
#
# @return [Contentful::Array, false]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is false the object type or is it something like Bool? just curious i'm used to return comments showing the type or just the parameter name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no Boolean class in Ruby, there are TrueClass and FalseClass, of which true and false are singletons of.

end

# Issues the request that was made to fetch this response again.
# Only works for top-level resources
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind elaborating on what you mean by top-level here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


private

def create_files!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I don't understand this create_files method (or at least it's underlying purpose). So you are essentially storing a JSON file that has been localized?

Copy link
Contributor Author

@dlitvakb dlitvakb Jan 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wraps the Asset's File Raw JSON into File Objects for every locale


def initialize(item, configuration = {}, _localized = false, _includes = [], depth = 0)
@raw = item
@default_locale = configuration[:default_locale]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this configuration object/dictionary look like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a copy of the configuration object sent to the resource builder, can be seen here: https://github.com/contentful/contentful.rb/pull/113/files#diff-ccad056e91bbffbe74262ffa2994a804R277

It's non-essential and internal, if you want to create your own instances it's not required to send anything there.

message += "Retrying - Retries left: #{retries_left}"
message += "- Time until reset (seconds): #{reset_time}"
message
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return value if type.nil?

options = {}
options[:coercion_class] = KNOWN_TYPES[items.type] unless items.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a comment about the usage of these options would be helpful. I had to scroll back up to the coercion file to understand that they are basically for Array's

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually currently only works for Entries and Assets, Arrays have been purposely removed.

'Asset' => Asset,
'Array' => :array_or_sync_page,
'Array' => Array,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@default_locale = default_locale
@resource_mapping = default_resource_mapping.merge(resource_mapping)
@entry_mapping = default_entry_mapping.merge(entry_mapping)
def initialize(json, configuration = {}, localized = false, depth = 0, endpoint = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I'm a bit confused by the usage of the configuration. Did I miss a comment about it somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration object here is just to reduce the amount of things sent around, also, the same configuration options are required to be sent around to other places, so instead of having a thousand parameters, having a hash of configuration options seemed more reasonable.

Also, these options are internal, and non-required if someone wants to create a custom class

@dlitvakb dlitvakb merged commit 5a36daf into master Jan 19, 2017
@dlitvakb dlitvakb deleted the dl/cleanup-codebase branch January 19, 2017 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants